Help with combobox navigation to pages in website

Last post 08-09-2007 5:29 AM by nseresha. 4 replies.

Sort Posts:

  • Help with combobox navigation to pages in website

    06-17-2007, 9:19 PM

     Hi,

    I have been trying to modify this code that I got from asp101.com

    The basics of what I want is a combobox that navigates to different pages in website.

    I have tried creating a combobox on my own but get stuck when trying to code the actual navigation in the web.

     

    I tried modifying the below code  but I get countless error when I try to build and now the combobox does not show at all in the page content. PLEASE HELP.

    I am willing to modify the  existing code or start fresh.

    Below is the code that I am using on the page 

    <%@ Page Language="VB" MasterPageFile="~/MasterPage2.master" AutoEventWireup="true" Title="Welcome Guest"%>

    <script language="VB" script runat="server">

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
         

       
            Dim blnAutoNav As Boolean
           
            If Not Page.IsPostBack Then
                ' Create a new ListItemCollection
                Dim myLocations As New ListItemCollection()

                ' Add items to the collection
                myLocations.Add(New ListItem("Where do you want to go?", Request.ServerVariables("URL")))
                myLocations.Add(New ListItem("Request Membership", "http://www.url.com/page.aspx"))
                myLocations.Add(New ListItem("FAQS", "http://www.url.com/page.aspx"))
              

                ' Databind our DDL to the ListItemCollection we just filled
                ddlLocations.DataSource = myLocations
                ddlLocations.DataTextField = "Text"
                ddlLocations.DataValueField = "Value"
                ddlLocations.DataBind()
            End If

            ' Find out current auto-navigation status and add JS to handle it if needed.
            If Request.QueryString("auto") = "True" Then
                blnAutoNav = True
               
                ' This adds the javascript to automatically redirect to the selected
                ' location whenever a new item is selected in the dropdownlist.
                ddlLocations.Attributes("onchange") = "javascript:window.location = " _
                 & "document.frmNav.ddlLocations[document.frmNav.ddlLocations.selectedIndex].value;"
            Else
                blnAutoNav = False
            End If

            ' Add the link to this page that toggles the autonav to
            ' the opposite of its current setting.
            litAutoNavLink.Text = "<a href=""" & Request.ServerVariables("URL") _
             & "?auto=" & CStr(Not (blnAutoNav)) & """>Toggle Auto Navigation</a>"
        End Sub

        Sub btnGo_Click(ByVal sender As Object, ByVal e As EventArgs)
            Response.Redirect(ddlLocations.SelectedItem.Value)
        End Sub

    </script>

    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1">

    <body>

    <form id="frmNav" runat="server">

    <asp:DropDownList id="ddlLocations" runat="server" />

    <asp:Button id="btnGo" runat="server"
        Text    = "Go"
        OnClick = "btnGo_Click"
    />

    <p>
    <asp:literal id="litAutoNavLink" runat="server" />
    </p>

    </form>

    <hr />


    </body>

    </asp:Content>
     

     

  • Re: Help with combobox navigation to pages in website

    06-17-2007, 9:55 PM
    Answer

     I now have the combobox being displayed but I get this error

    Content controls have to be top-level controls in a content page or a nested master page that references a master page.


    HttpException (0x80004005): Content controls have to be top-level controls in a content page or a nested master page that references a master page.]
    System.Web.UI.MasterPage.CreateMaster(TemplateControl owner, HttpContext context, VirtualPath masterPageFile, IDictionary contentTemplateCollection) +533
    System.Web.UI.Page.get_Master() +49
    System.Web.UI.Page.ApplyMasterPage() +17
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1368
    This error seems to indicate that the way I have placed the code is incorrect but I am unsure how to format it correctly.
     Here is the code below
    <%@ Page Language="VB" MasterPageFile="~/MasterPage2.master" AutoEventWireup="true" Title="Welcome Guest"%>
    <script language="VB" script runat="server">

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)



    Dim blnAutoNav As Boolean

    If Not Page.IsPostBack Then
    ' Create a new ListItemCollection
    Dim myLocations As New ListItemCollection()

    ' Add items to the collection
    myLocations.Add(New ListItem("Where do you want to go?", Request.ServerVariables("URL")))
    myLocations.Add(New ListItem("Request Membership", "http://www.cabletrades.com/CreateAccount.aspx"))
    myLocations.Add(New ListItem("FAQS", "http://www.cabletrades.com/FAQS.aspx"))
    myLocations.Add(New ListItem("View Add Funds", "http://www.cabletrades.com/GAddFunds.aspx"))
    myLocations.Add(New ListItem("View Withdraw Funds", "http://www.cabletrades.com/GWithdraw.aspx"))
    myLocations.Add(New ListItem("View History", "http://www.cabletrades.com/GHistory.aspx"))
    myLocations.Add(New ListItem("View Profile", "http://www.cabletrades.com/GProfile.aspx"))

    ' Databind our DDL to the ListItemCollection we just filled
    ddlLocations.DataSource = myLocations
    ddlLocations.DataTextField = "Text"
    ddlLocations.DataValueField = "Value"
    ddlLocations.DataBind()
    End If

    ' Find out current auto-navigation status and add JS to handle it if needed.
    If Request.QueryString("auto") = "True" Then
    blnAutoNav = True

    ' This adds the javascript to automatically redirect to the selected
    ' location whenever a new item is selected in the dropdownlist.
    ddlLocations.Attributes("onchange") = "javascript:window.location = " _
    & "document.frmNav.ddlLocations[document.frmNav.ddlLocations.selectedIndex].value;"
    Else
    blnAutoNav = False
    End If

    ' Add the link to this page that toggles the autonav to
    ' the opposite of its current setting.
    litAutoNavLink.Text = "<a href=""" & Request.ServerVariables("URL") _
    & "?auto=" & CStr(Not (blnAutoNav)) & """>Toggle Auto Navigation</a>"
    End Sub

    Sub btnGo_Click(ByVal sender As Object, ByVal e As EventArgs)
    Response.Redirect(ddlLocations.SelectedItem.Value)
    End Sub

    </script>




    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1">

    <form id="frmNav" runat="server">
    &nbsp;


    <p>
    <asp:literal id="litAutoNavLink" runat="server" />
    </p>

    </form>


    <div style="right: -342px; width: 359px; position: relative; top: -83px; height: 44px">

    <asp:DropDownList id="ddlLocations" runat="server" style="position: relative" Width="201px" />

    <asp:Button id="btnGo" runat="server"
    Text = "Go"
    OnClick = "btnGo_Click" style="position: relative"
    /></div>



    </asp:Content>

     
  • Re: Help with combobox navigation to pages in website

    06-19-2007, 4:32 AM
    Answer

    Hi,

    You use the masterpage,  the master page also contains all of the top-level HTML elements for a page, such as html, head, and form. So it is not necessary in the content page, if the content page  contains the HTML elements , it will give error messages.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    Yours sincerely,
    Amanda Wang
    Microsoft Online Community Support
  • Re: Help with combobox navigation to pages in website

    06-19-2007, 12:25 PM

     Thanks so much. This has solved my problem

  • Re: Help with combobox navigation to pages in website

    08-09-2007, 5:29 AM
    • Loading...
    • nseresha
    • Joined on 06-25-2007, 1:52 AM
    • Posts 8

    Hi

    I am stuck with similar issue. I am trying to provide AJAX functionality in some only some pages of my site. For this reason, I have put script manager and enablepartialrendering=true in master pages and updatepanel in same master page for that content place holder. But I still get that flickering.

    So, I've moved the updatepanel to necessary pages and added them before contentplaceholder. Error - content control have to be top-level controls....

    when I tried to put the updatepanel inside contentplaceholder with VS->options->TextEditor->HTML->donot show errors, I didnot get the error but i could still able to observe Flickering.

    Please help how to troubleshoot the issue.

    Thanks in advance

    nseresha.

Page 1 of 1 (5 items)
Microsoft Communities
Page view counter