Solved

Opening a new window in ASP.NET/VB.NET

Posted on 2011-09-29
16
420 Views
Last Modified: 2012-06-27
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
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

Open in new window

0
Comment
Question by:Ammar Iqbal
  • 7
  • 5
  • 3
  • +1
16 Comments
 
LVL 12

Expert Comment

by:jagssidurala
ID: 36850046
0
 
LVL 12

Expert Comment

by:jagssidurala
ID: 36850634
0
 
LVL 1

Author Comment

by:Ammar Iqbal
ID: 36890148
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

Open in new window

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

Open in new window

0
 
LVL 12

Expert Comment

by:rajapandian_81
ID: 36890672
Hi,

Move the code which is inside "Opennewwindow" function to "Page_Load" event.
0
 
LVL 1

Author Comment

by:Ammar Iqbal
ID: 36890924
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"
0
 
LVL 12

Accepted Solution

by:
rajapandian_81 earned 500 total points
ID: 36891013
ok.. So do you want to open new window in button click event, the new window url will be determined in button click event.

Try below code:
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "NewWindow", "<script type=\"text/javascript\"> window.open('" & PagePath & "'); </script>")

Open in new window

0
 
LVL 12

Assisted Solution

by:rajapandian_81
rajapandian_81 earned 500 total points
ID: 36891029
Try below code:
Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "NewWindow", "<script type='text/javascript'> window.open('" & PagePath & "'); </script>")

Open in new window

0
 
LVL 1

Author Comment

by:Ammar Iqbal
ID: 36891096
wherei try this code.. IS it in the bytton on click event handler?
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 12

Expert Comment

by:rajapandian_81
ID: 36891119
YES.
0
 
LVL 1

Author Comment

by:Ammar Iqbal
ID: 36891123
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
0
 
LVL 12

Expert Comment

by:rajapandian_81
ID: 36891135
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.
0
 
LVL 1

Author Comment

by:Ammar Iqbal
ID: 36891140
code is posted in the first post of this question
0
 
LVL 1

Author Comment

by:Ammar Iqbal
ID: 36892519
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.
0
 
LVL 12

Expert Comment

by:jagssidurala
ID: 36893146
May be you are using ajax(update panels) then the script calling in button click should be as below.

ScriptManager.RegisterStartupScript(this, this.GetType(), "NewWindow", "<script type=\"text/javascript\"> window.open('" & PagePath & "'); </script>", false);

0
 
LVL 1

Author Comment

by:Ammar Iqbal
ID: 36895962
By using scriptmanger.registerstartupscript(....), 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
0
 
LVL 28

Expert Comment

by:sybe
ID: 36901838
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';this.form.submit();" />
</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.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now