Friday, July 8, 2011

refresh the webpage using javascript

__doPostBack is one of the best method to use for refreshing a webpage in asp.net webapplication.The code is given as below as follows:

1.First open a new WebSite in VS studio and create two aspx web pages as Sample1.aspx and Sample2.aspx.

2.Let Sample2.aspx be a popup window and Sample1.aspx is a normal webpage.
Write the below in the heag tag of the Sample2.aspx which page to be loaded.

<html>
<head>
<script language="javascript">
function Refresh()
{
__doPostBack('btnClick',' ');
location.reload();
}
<script>
<head>
&lthtml>

3.Write the following code in the normal sample1.aspx page where u want to load the pop up window.

protected void Page_Load()
{
if (IsPostBack)
{
string arg = Request.Form["__EVENTTARGET"];
string val = Request.Form["__EVENTARGUMENT"];

if (arg == "btnClick")
{
//Write the code as what to populate......
}
}

4.In the pop up window if we have a button,the write the below code as follows:

protected void btnClose_Click(object sender, EventArgs e)
{
Response.Write("");

}



In this way you can use the javascript code for refreshing a page....