Sunday, 28 April 2013 13:56

how to refresh a page using javascript from code behind in asp.net

Written by 
Rate this item
(2 votes)

in one of my application i had to refresh a page when the page is
loaded from a click command.so i used javascript to do that but i
had to do it from code behind by registering javascript -

in page load method of the page i added -

protected void Page_Load(object sender, EventArgs e)
{

if (Session[IDNumber.ToString() + "reload"] != null) { Session[IDNumber.ToString() + "reload"] = null; }
else
{
Session[IDNumber.ToString() + "reload"] = "true";
Page.ClientScript.RegisterStartupScript(typeof(Page), Guid.NewGuid().ToString(),
"<script type='text/javascript'>window.location.reload(true);</script>");
}

}

in the aboved codes the IDNumber is a unique id of the user i passes to the
page as query string.all those codes i did not show here but wrote what needed
to reload a page on first page load.

Read 10589 times
Super User

Email This email address is being protected from spambots. You need JavaScript enabled to view it.

Latest discussions

  • No posts to display.