Solved

How to combine masterpage with dynamically created radiobuttonlist

Posted on 2013-11-11
4
374 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Great reference. Now it works!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

763 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now