Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to combine masterpage with dynamically created radiobuttonlist

Posted on 2013-11-11
4
Medium Priority
?
409 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1000 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

618 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