Indeed you have to do use client-side code, but you actually can generate that code from server-side, al you have to do is append this code to Page.Load event handler of your ASP.NET web form.
What I do in this code is to generate the actual client side script line by line using a StringBuilder for concatenation, then I have all the script code rendered in the client HTML (immediately below the opening tag of the Page object’s <form runat=”server ”> ) when the page loads using the RegisterClientS criptBlock.
Then, using the button's Attributes collection, I map the onclick client event of the ASP.NET button to the name of the script I previously generated.
This will cause you ASP.NET button to respond to the onclick client-side event by opening a new browser window, you can customize the new browser window, in my case i did it like a popup, so that I can append some parameters to the query string.
Hope this helps,
Alan Ferrandiz
MCT;MCDBA,MCSD for .NET
MSF Practitioner
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load
Dim oStringBuilder As New System.Text.Str ingBuilder()
oStringBuilder. Append("<SCRIPT language=""java script"">")
oStringBuilder. Append(vbNewLin e)
oStringBuilder. Append(" <!--")
oStringBuilder. Append(vbNewLin e)
oStringBuilder. Append(" function popup(url) {")
oStringBuilder. Append(vbNewLin e)
oStringBuilder. Append(" newwindow = window.open(url ,'name','height =300,width=450, scrollbars=no') ;")
oStringBuilder. Append(vbNewLin e)
oStringBuilder. Append(" if (window.focus) {newwindow.focu s()}")
oStringBuilder. Append(vbNewLin e)
oStringBuilder. Append(" return false;")
oStringBuilder. Append(vbNewLin e)
oStringBuilder. Append(" }")
oStringBuilder. Append(vbNewLin e)
oStringBuilder. Append(" //-->")
oStringBuilder. Append(vbNewLin e)
oStringBuilder. Append("</SCRIPT>")
Page.RegisterCl ientScriptBlock ("popup", oStringBuilder. ToString)
Button1.Attribu tes.Add("onClic k", "return popup('popup.as px?value=someva lue');")
End Sub
"Novice" <6tc1ATqlinkDOT queensuDOTca> escribió en el mensaje news:C4******** *************** ***********@mic rosoft.com...
Hi all, as you can see from the subject, I'm try to use an asp:button to create a new browser window and output contents to new window.
But default if I do the:
Response.Write( "...")
The output gets sent directly to the window or frame that the button was contained in - if I was using regular anchor links I could just specify the target - i.e.:
<a href="http://...." target="nameNot InCurrentFrames et">something </a>
Thanks,
Novice