Solved

Open new page after choosing drop down list selection

Posted on 2009-07-05
7
306 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

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 …
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

707 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

16 Experts available now in Live!

Get 1:1 Help Now