Thursday, April 15, 2010

Open a page in the same browser using JavaScript without Postback

Problem:

Had a requirement to open up a page in the same browser window without postback to the existing page.

Solution:

In JavaScript, window.Open(...) is there to open a page in a new window. With the value of _self as a second parameter to the Window.Open, we could open the page in the same browser window.

Code Snippet:

#1 Using Image Button


OnClientClick="Javascript:window.open('Format.aspx','_self',null,false);return false;" />

#2 Using href anchor tag


href="javascript:window.open('Format.aspx','_self');" style="text-decoration:underline" id="A1" >Click...Here

I have opened the page called "Format.aspx" using window.open with the second parameter as "_self" on the OnClientclick of ImageButton. Finally give the return false to not posted back to the existing page.

Reference:
Refer the below Microsoft knowledge base library for more info.



No comments:

Post a Comment