Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Open new page after choosing drop down list selection

Posted on 2009-07-05
7
309 Views
Last Modified: 2013-11-26
I have an asp.net vb page that has a form.  Within the form, is  a dropdown list that asks if a person has more information to include.  The drop downlist has the following options: "Yes" and "No".  I would like to launch a new webpage "moreinfo.aspx" if the answer "Yes" is selected.  I would like the page to be on top of the form page. Can someone help?
0
Comment
Question by:OB1Canobie
  • 3
  • 3
7 Comments
 
LVL 3

Expert Comment

by:sandip-mishra
ID: 24782028
Hi .... Try this, it works fine for me...

aspx.....

<asp:DropDownList ID="DropDownList1" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" AutoPostBack="true">
            <asp:ListItem>Select</asp:ListItem>
            <asp:ListItem>Yes</asp:ListItem>
            <asp:ListItem>No</asp:ListItem>
        </asp:DropDownList>

aspx.cs

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (DropDownList1.SelectedValue == "Yes")
        {
            String s = @"<script language='javascript' type='text/javascript'>";
            s += "window.open('http://www.google.co.in');";
            s += "</script>";
            Page.RegisterStartupScript("OpenWindow", s);
        }
    }
0
 
LVL 10

Expert Comment

by:Espavo
ID: 24782672
The way that I would do this is by using a ModalPopUp (instead of opening a new window)...
The form would have to be a part of the original page though...
0
 

Author Comment

by:OB1Canobie
ID: 24785538
sandip-mishra,

what language is your example written in?  This does not appear to be vb.  Can you rewrite in vb?
0
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
LVL 3

Expert Comment

by:sandip-mishra
ID: 24791004
hi...

here is the VB coding....

Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
       If DropDownList1.SelectedValue = "Yes" Then
            Dim s As [String] = "<script language='javascript' type='text/javascript'>"
            s += "window.open('http://www.google.co.in');"
            s += "</script>"
            Page.RegisterStartupScript("OpenWindow", s)
        End If
   End Sub


I have converted the C# code to VB code. Hope it works for you too.

Regards

Sandip Mishra
0
 

Author Comment

by:OB1Canobie
ID: 24795817
sandip-mishra:
I'm getting an error with the vb code above.  The error is occuring on the line "Page.RegisterStartupScript("OpenWindow", s)",  any ideas of how to fix?

Warning      1      'Public Overridable Sub RegisterStartupScript(key As String, script As String)' is obsolete: 'The recommended alternative is ClientScript.RegisterStartupScript(Type type, string key, string script). http://go.microsoft.com/fwlink/?linkid=14202'.
0
 
LVL 3

Accepted Solution

by:
sandip-mishra earned 500 total points
ID: 24800536
hi... try with t his... its working  fine wit h me... I generally write my codes in C#.  SO had just converted the C# code into VB using a tool and had executed the code. It is working fine for me. Hope it works for u too... :)

Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
        If DropDownList1.SelectedValue = "Yes" Then
            If (Not Me.IsStartupScriptRegistered("Startup")) Then

                Dim s As [String] = "<script language='javascript' type='text/javascript'>"
                s += "alert('hi');window.open('http://www.google.co.in');"
                s += "</script>"
                Me.RegisterStartupScript("Startup", s)
            End If
        End If
    End Sub
End Class

Regards

Sandip Mishra
0
 

Author Closing Comment

by:OB1Canobie
ID: 31599936
This code is great.  Thanks for the help.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

828 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