Ammar Iqbal
asked on
Opening a new window in ASP.NET/VB.NET
The attached code opens a form with the query string a parmeter in the same browser window. I need to open this form in a new window in stead of a same window.
Urgently required
Urgently required
If Not Request("eid") Is Nothing Then
Dim strEvtGUID As String = "Select EventGUID FROM Events WHERE EventID='" + Request("eid") + "' "
Dim evtGUID As Guid = Dbc.ExecScalar(strEvtGUID, PageDbConn)
Response.Redirect(String.Format("~/events/RegForm.aspx?id={0}", evtGUID))
End If
ASKER
Please see my attached scripts . I manged to open a new window by clicking 2 times on a button using this script . I want to do this by only one click.
Public Shared Sub Opennewwindow(ByVal Opener As System.Web.UI.WebControls.WebControl, ByVal PagePath As String)
Dim Clientscript As String
Clientscript = "window.open('" & PagePath & "')"
Opener.Attributes.Add("Onclick", Clientscript)
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
' Me.mpe.Show()
Try
'If Not Request("eid") Is Nothing Then
Dim strEvtGUID As String = "Select EventGUID FROM Events WHERE EventID='" + Request("eid") + "' "
Dim evtGUID As Guid = Dbc.ExecScalar(strEvtGUID, PageDbConn)
Dim str As String = String.Format("../../../../events/RegForm.aspx?id={0}", evtGUID)
Catch ex As Exception
End Try
End Sub
Hi,
Move the code which is inside "Opennewwindow" function to "Page_Load" event.
Move the code which is inside "Opennewwindow" function to "Page_Load" event.
ASKER
but how, i need to get page_path in this code from the on click event handler of button.how can this be accomodated. Page_pathh will only be generated when i click "button1"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
wherei try this code.. IS it in the bytton on click event handler?
YES.
ASKER
i hav etried this the button on click event ahandler. it does not go up after single click infact it does not open at all
Can you post the code of Button1_Click event handler?
Problem may be in some other line. Because the code provided by me works fine here.
Problem may be in some other line. Because the code provided by me works fine here.
ASKER
code is posted in the first post of this question
ASKER
Hei rajapandian_81,
Yes i ccan open ta newwindow using your code script. but the problem is that i haveto press Ctrl-alt along with pressing the mouse button. but the requirement of my client is that we should be open a new window withourt clicking vtrl + alt .
it n be able to open simply by csingle clicking button.
Yes i ccan open ta newwindow using your code script. but the problem is that i haveto press Ctrl-alt along with pressing the mouse button. but the requirement of my client is that we should be open a new window withourt clicking vtrl + alt .
it n be able to open simply by csingle clicking button.
May be you are using ajax(update panels) then the script calling in button click should be as below.
ScriptManager.RegisterStar tupScript( this, this.GetType(), "NewWindow", "<script type=\"text/javascript\"> window.open('" & PagePath & "'); </script>", false);
ScriptManager.RegisterStar
ASKER
By using scriptmanger.registerstart upscript(. ...), it does not open at all, and by using page.registerstartupscript (...) it opens bu clikcing ctrl-alt , adn mouse click(pop up blocker )in internet explorer , and there is not pop up blocker instaled in my broweser.
on safari , it does not open at all, when i use page.registerstartup script
on safari , it does not open at all, when i use page.registerstartup script
Windows and frames are client-side concepts.
If you want to the browser to open a new window then either you need to send some javascript to the browser, or specify a target.
In this case it seems easier to specify a target in the form. The new window will be opened when the user clicks the button.
<form target="_blank" method="post" action="yourscript.aspx">
<input type="submit" value="Ok" />
</form>
If you need, you can write a script that changes the target on the click on the button.
<form method="post" action="yourscript.aspx">
<input type="button" value="Ok" onclick="this.form.target= '_blank';t his.form.s ubmit();" />
</form>
I realize that this is basic HTML/javascript, and that ASP.Net sometimes makes it very hard to use basic HTML coding. But maybe it is of use to you.
If you want to the browser to open a new window then either you need to send some javascript to the browser, or specify a target.
In this case it seems easier to specify a target in the form. The new window will be opened when the user clicks the button.
<form target="_blank" method="post" action="yourscript.aspx">
<input type="submit" value="Ok" />
</form>
If you need, you can write a script that changes the target on the click on the button.
<form method="post" action="yourscript.aspx">
<input type="button" value="Ok" onclick="this.form.target=
</form>
I realize that this is basic HTML/javascript, and that ASP.Net sometimes makes it very hard to use basic HTML coding. But maybe it is of use to you.
below are the links for the imlementation
http://www.dotnetcurry.com/ShowArticle.aspx?ID=99
http://aspguy.wordpress.com/2008/06/09/how-to-open-popup-windows-in-iefirefox-and-return-values-using-aspnet/