|
Written by Sriram V
Have you ever had a form lower down in a page and you wanted to refocus on it after a postback? You can do this without using a redirect (e.g. if your .NET control did a postback and you didn't want to use a redirect).
Just put an anchor in the page near your control and in the code the processes the form, add as the last line:
' Javascript used to reposition window after a postback
Dim scriptStr As String = "<script language='javascript'>location.href=""#SigDatesDataGrid"";</script>"
Me.RegisterStartupScript("Startup", scriptStr)
You can do this automatically by using the value of Request.Form("__EVENTTARGET") but you need to write out the anchor automatically as well. Note: the start up script can also be used to close the editing window when editing is completed and so on. This looks a little cleaner in code than writing out the JavaScript directly to the page, since we are registering the script with the page.
Full Article: http://www.dotnetjunkies.com/Article/E474B0FC-20D2-48B3-93B5-DC4CB3C4A1AB.dcik
|