• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 418
  • Last Modified:

How to combine masterpage with dynamically created radiobuttonlist

Hi!

I am using a masterpage from which I generate new webforms. I have no problem to add sql-datasource and e.g. gridviews in the new pages, but when I tried to add radiobuttonlist and label which should be bound to a dynamically added datatable , I only get it to work if the datatable is created in the masterpage.

The big drawback is that my radiobuttonlist and label is placed on all pages.

In reality the radiobuttonlist will contain more complex data but I placed nonsens-content for testing.

picturetoclairfy

The error I get reads something like this
Control 'ctl00_head_RadioButtonList1_0' of type 'RadioButton' must be placed inside a form tag with runat=server



This is my masterpage which now contains the creation of the data table, the radiobuttonlist and the label.

<
%@ Master Language="VB" CodeFile="MasterPage.master.vb" Inherits="MasterPage" %>
<%@ Import Namespace="System.Data" %>
<!DOCTYPE html>
<script language="VB" runat="server">
    Function CreateDataSource() As ICollection
        Dim dt As New DataTable()
        Dim dr As DataRow

        dt.Columns.Add(New DataColumn("IntegerValue", GetType(Int32)))
        dt.Columns.Add(New DataColumn("StringValue", GetType(String)))
        dt.Columns.Add(New DataColumn("DateTimeValue", GetType(DateTime)))
        dt.Columns.Add(New DataColumn("BoolValue", GetType(Boolean)))
        dt.Columns.Add(New DataColumn("CurrencyValue", GetType(Double)))

        Dim i As Integer
        For i = 0 To 8
            dr = dt.NewRow()

            dr(0) = i
            dr(1) = "Item " + i.ToString()
            dr(2) = DateTime.Now
            If (i Mod 2) <> 0 Then
                dr(3) = True
            Else
                dr(3) = False
            End If
            dr(4) = 1.23 * (i + 1)

            dt.Rows.Add(dr)
        Next i

        Dim dv As New DataView(dt)
        Return dv
    End Function

    Sub Page_Load(sender As Object, e As EventArgs)
        If Not IsPostBack Then
            RadioButtonList1.Items.Add(New ListItem("Carbon", "C"))
            RadioButtonList1.AppendDataBoundItems = True
            RadioButtonList1.DataSource = CreateDataSource()
            RadioButtonList1.DataTextField = "StringValue"
            RadioButtonList1.DataValueField = "CurrencyValue"
            RadioButtonList1.DataBind()
        End If
    End Sub

    Sub Index_Changed(sender As Object, e As EventArgs)
        Label1.Text = "You selected " & RadioButtonList1.SelectedItem.Text & _
            " with a value of : " & RadioButtonList1.SelectedItem.Value & "."
    End Sub



</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <meta name="keywords" content="" />
<meta name="description" content="" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Equivalency by FCT</title>
<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
    <asp:ContentPlaceHolder id="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        
    <div id="wrapper">
	<div id="header">
		<div id="logo">
			<h1>Gymnasiestudera.se<a href="#"> </a></h1>
			<p> Välkommen till Gymnasiestudera i Östergötland inför läsåret 2014/2015</p>
		</div>
		<div id="menu">
			<ul>
				<li class="first current_page_item"><a href="default3.aspx">Hem</a></li>
				<li><a href="information.aspx">Information</a></li>
				<li><a href="#">Utbildningar</a></li>
				<li><a href="syv.aspx">Kontakta Syv</a></li>
				<li><a href="https://www.gymnasiestudera.se/gymnasieintag/stats.asp">Statistik</a></li>
				
                <li><a href="#">Kontakta Antagningent</a></li>
			</ul>
		</div>
	</div>
	<!-- end #header -->
	<div id="page">
		<div id="page-bgtop">
			<div id="page-bgbtm">
				<div id="content">
                    <asp:RadioButtonList id="RadioButtonList1" 
            OnSelectedIndexChanged="Index_Changed"
            AutoPostBack="true"
            runat="server"/>
                    <asp:Label id="Label1" runat="server"/>
                    <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
       

       <br />

       
        
					<div class="post">
						<h2 class="title"><a href="#">Vilka utbildningar finns i östergötland<a href="#"> </a></h2>
                            <p class="meta">
                                <a href="#"></a>
                            </p>
                            <div class="entry">
                                <p>
                                    <img src="images/img08.jpg" width="538" height="200" alt="" /></p>
                                <p>
                                    This is om free template is released under a mmons.org/licenses/by/3.0/">Creative Commons Attribution 3.0, so you’re pretty much free to do whatever you want with it (even use it commercially provided you keep the links in the footer intact. Aside from that, have fun with it. </p>
							<p class="links"><a href="#">Read More</a>&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;<a href="#" title="b0x w">Comments</a></p>
						</div>
					</div>
					<div class="post">
						<h2 class="title"><a href="#">Lorem ipsum sed aliquam</a></h2>
						<p class="meta">Posted by <a href="#">Someone</a> on October 8, 2010
							&nbsp;&bull;&nbsp; <a href="#" class="comments">Comments (64)</a> &nbsp;&bull;&nbsp; <a href="#" class="permalink">Full article</a></p>
						<div class="entry">
							<p><img src="images/img09.jpg" width="538" height="200" alt="" /></p>
							<p>Sed lacus. Donec lectus. Nullam pretium nibh ut turpis. Nam bibendum. In nulla tortor, elementum vel, tempor at, varius non, purus. Mauris vitae nisl nec metus placerat consectetuer. Donec ipsum. Proin imperdiet est. Phasellus <a href="#">dapibus semper urna</a>. Pellentesque ornare, orci in consectetuer hendrerit, urna elit eleifend nunc, ut consectetuer nisl felis ac diam. Etiam non felis. Donec ut ante. In id eros. Suspendisse lacus turpis, cursus egestas at sem.  Mauris quam enim, molestie in, rhoncus ut, lobortis a, est.</p>
							<p class="links"><a href="#">Read More</a>&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;<a href="#">Comments</a></p>
						</div>
					</div>
					<div style="clear: both;">&nbsp;</div>
				</div>
				<!-- end #content -->
				<div id="sidebar">
					<ul>
						<li>
							<div id="search" >
								<form method="get" action="#">
									<div>
										<input type="text" name="s" id="search-text" value="" />
										<input type="submit" id="search-submit" value="GO" />
									</div>
								</form>
							</div>
							<div style="clear: both;">&nbsp;</div>
						</li>
						<li>
							<h2>Aliquam tempus</h2>
							<p>Mauris vitae nisl nec metus placerat perdiet est. Phasellus dapibus semper consectetuer hendrerit.</p>
						</li>
						<li>
							<h2>Categories</h2>
							<ul>
								<li><a href="#">Aliquam libero</a></li>
								<li><a href="#">Consectetuer adipiscing elit</a></li>
								<li><a href="#">Metus aliquam pellentesque</a></li>
								<li><a href="#">Suspendisse iaculis mauris</a></li>
								<li><a href="#">Urnanet non molestie semper</a></li>
								<li><a href="#">Proin gravida orci porttitor</a></li>
							</ul>
						</li>
						<li>
							<h2>Blogroll</h2>
							<ul>
								<li><a href="#">Aliquam libero</a></li>
								<li><a href="#">Consectetuer adipiscing elit</a></li>
								<li><a href="#">Metus aliquam pellentesque</a></li>
								<li><a href="#">Suspendisse iaculis mauris</a></li>
								<li><a href="#">Urnanet non molestie semper</a></li>
								<li><a href="#">Proin gravida orci porttitor</a></li>
							</ul>
						</li>
						<li>
							<h2>Archives</h2>
							<ul>
								<li><a href="#">Aliquam libero</a></li>
								<li><a href="#">Consectetuer adipiscing elit</a></li>
								<li><a href="#">Metus aliquam pellentesque</a></li>
								<li><a href="#">Suspendisse iaculis mauris</a></li>
								<li><a href="#">Urnanet non molestie semper</a></li>
								<li><a href="#">Proin gravida orci porttitor</a></li>
							</ul>
						</li>
					</ul>
                    </asp:ContentPlaceHolder>
				</div>
				<!-- end #sidebar -->
				<div style="clear: both;">&nbsp;</div>
			</div>
		</div>
	</div>
	<!-- end #page -->
</div>
<div id="footer">
	<p>Copyright (c) 2008 Sitename.com. All rights reserved. Design by <a href="http://www.freecsstemplates.org/" rel="nofollow">FreeCSSTemplates.org</a>.</p>
</div>
<!-- end #footer -->
    
    </div>
    </form>
</body>
</html>

Open in new window



This i a webform generated from the masterpage I would like to have the radiobuttonlist, label etc. only in this page.

<%@ Page Title="" Language="VB" MasterPageFile="~/15beta/MasterPage.master" %>

<script runat="server">

</script>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
</asp:Content>

Open in new window

0
marcgu
Asked:
marcgu
  • 2
  • 2
1 Solution
 
Bob LearnedCommented:
Since you are using a strong-typed master page, you should be able to add a method or a property to pass the data to the master page from the content page.
0
 
marcguAuthor Commented:
Hi! OK, I, interpret your answer as it should be possible. I' ll give it another try and give feedback.
0
 
Bob LearnedCommented:
It is most definitely possible, and here is a proof-of-concept article:

Passing Information Between Content and Master Pages
http://www.4guysfromrolla.com/articles/013107-1.aspx
0
 
marcguAuthor Commented:
Great reference. Now it works!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now