Solved

How to combine masterpage with dynamically created radiobuttonlist

Posted on 2013-11-11
4
379 Views
Last Modified: 2013-11-15
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
Comment
Question by:marcgu
  • 2
  • 2
4 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 39640439
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
 

Author Comment

by:marcgu
ID: 39648957
Hi! OK, I, interpret your answer as it should be possible. I' ll give it another try and give feedback.
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 39649107
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
 

Author Closing Comment

by:marcgu
ID: 39651622
Great reference. Now it works!
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

Suggested Solutions

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

810 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