Monday, March 26, 2012

passing variable to open a new window

I am new to asp.net. I am wondering how I can open a new window from a button or link. I need to pass a value so both windows are linked. I will appreciate any help, code vb.net

The main page has a label is that stores the ID number, I need to pass this value so I can display in the new window information about this id. Please help. Thanks.

use the Querystring to pass variables to other pages

ie.


Response.Redirect("www.myplace.com/mynewpage.aspx?someValue=399393","_blank");

check this out

http://www.codeproject.com/aspnet/QueryString.asp

hth,

mcm


how about javascript?

<asp:button onclientClick='window.open(.....);' Text='Open New Window' runat=server />


Thanks for the answer. However, I need to open a new window. Could you please help me out? I am using vb.net. Thanks.

javascript DOES open a new window.

read about it. -->http://www.javascript-coder.com/window-popup/javascript-window-open.phtml

mcm


You can test the below code in page_load event which will open a new window using javascript

Page.ClientScript.RegisterStartupScript(me.GetType(),"open","window.open('WebForm2.aspx?id=123','','height=400,width=300');",true)

Where WebForm2.aspx is the name of the window you would like to open. Now in webform2 you can get the value of id using

Dim id as String = Request.QueryString("id")

HC


Yes. But I need to pass from the current window, a value which is saved in a label, to the new window. Thanks for the answer.

dim yourPassInVar as string

Page.ClientScript.RegisterStartupScript(me.GetType(),"open","window.open('WebForm2.aspx?id='" + yourPassInVar + ",'','height=400,width=300');",true)

How about this?



In the current window page_load event use the below code if you want the window to open direclty when the page is being loaded

Page.ClientScript.RegisterStartupScript(me.GetType(),"open","window.open('WebForm2.aspx?id=' + '"+Label1.Text+"','','height=400,width=300');",true)

If you want for example to open it on button click event use the below code

Button1.Attributes.Add("onclick","window.open('WebForm2.aspx?id=' + '"+Label1.Text+"','','height=400,width=300');")

Where Button1 is the button you want to open the window when being clicked

HC


Thanks. How can I do it with a button? When clicking on the button, the variable that holds the id value let's say 123 will be passed to webform2.aspx. Again, thanks for the help.

Great. Thank you for all the help!

;-)

0 comments:

Post a Comment