Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Wanna open a new window on a button click. 4

Status
Not open for further replies.

qwert231

Programmer
Sep 4, 2001
756
US
I have a ASP.Net button that does some code when it's clicked, but I would also like it to open a new window with another page in it. How can I have that fire from ASP?
 
Button.Attributes.Add("OnClick", "javascript:window.open('page to open')")

Put that in either your page_load event, or in your page initialize. This will also work for any control that has an onClick event.

D'Arcy
 
Will this work for other events? Such as setting focus to a text box...and then when a button is pressed...set focus to a list box??

DLC
 
Yes, it should work for other events as well.

If you'd like a handy way to set the focus of a control without having to write code over and over again, use this handy little function:

Private Sub SetFocus(ByVal ctrl As System.Web.UI.Control)
Dim s As String =
&quot;<SCRIPT language='javascript'>document.getElementById('&quot;
& ctrl.ID & &quot;').focus() </SCRIPT>&quot;

RegisterStartupScript(&quot;focus&quot;, s)

End Sub

So when calling it, you just need to pass a reference to the control.
i.e.
SetFocus(TextBox1)

hth

D'Arcy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top