By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,925 Members | 732 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,925 IT Pros & Developers. It's quick & easy.

DropDownList MasterPage Error Navigate To URL erro help.

P: 20
I hope someone can help me. I have an error that I can not seem to figure out. All I need is an unbound dropdownlist to navigate to urls withing the website. I have gotten as far as to populate field but I am stuck at this point. I am new to asp.net and this is my first website.

Below is my code please help.

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


--------------------------------------------------------------------------------
This is the error

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(TemplateCont rol 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.url.com/CreateAccount.aspx"))
myLocations.Add(New ListItem("FAQS"))


' 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>
Jun 19 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.