Monday, August 17, 2009

Open a PopUp Window on the ASP.NET Button Click event and pass Parameters

A User asked me how to Open a PopUp window when the user clicks on an ASP.NET Button Server Control. He also wanted to pass parameters to the url. Here's how it is done:

C#


protected void Button1_Click(object sender, EventArgs e)


{


string queryString =


"http://localhost:39208/TreeView.aspx?param1="


+ TextBox1.Text.Trim();


string newWin =


"window.open('" + queryString + "');";


ClientScript.RegisterStartupScript


(this.GetType(), "pop", newWin, true);


}




VB.NET


Protected Sub Button1_Click(ByVal sender As Object, _


ByVal e As EventArgs)


Dim queryString As String = _


"http://localhost:39208/TreeView.aspx?param1=" & _


TextBox1.Text.Trim()


Dim newWin As String = _


"window.open('" & queryString & "');"


ClientScript.RegisterStartupScript(Me.GetType(), _


"pop", newWin, True)


End Sub

No comments:

Post a Comment