Finding Value of Dynamic Control in MasterPage/ContentPage System

G

Guest

I have a page that creates dynamic textboxes based on the number of
fields a user chooses to fill out.

This process worked great when the page was standalone. However, when I
move to a Content/MasterPage setup, the MasterPage Form seems to be
interfering with the ability of my code to retrieve the value in the
dynamic control.


Are there any ideas on why this is happening or how to work-around the
problem? What is the syntax to find a dynamic control within a form
established on a Master Page? The two methods I have tried so far
always gets me the "Object reference not set to an instance of an
object" error.


A quick example is below. The name of the form established in the
MasterPage is "frmForm". I must place the form tags within the
MasterPage because of the presence of a SiteMap menu control that
resides in the MasterPage.


<%@ Page Language="VB" MasterPageFile="~/Sys_Masters/MasterPage.master"
title="Dynamic Control in Master Page" %>


<asp:Content ID="Content1" ContentPlaceHolderID="cphContent"
Runat="Server">


<script runat="server">


Sub Page_Load()


Dim txtbxTextBox As New TextBox()
txtbxTextBox.ID = "txtbxTextBox"
phPlaceHolder.Controls.Add(txtbxTextBox)


End Sub


Sub btnSubmit_OnClick(ByVal sender As Object, ByVal e As
System.EventArgs)


Dim txtbxTextBox As New TextBox()


'// Neither of the two methods below finds the control
'txtbxTextBox =
Master.FindControl("frmForm").FindControl("phPlaceHolder").FindControl("txt­bxTextBox")
'txtbxTextBox = CType(Master.FindControl("frmForm").FindControl
"phPlaceHolder").FindControl("txtbxExample"), TextBox)


lblValue.Text = txtbxTextBox.Text


End Sub


</script>


<asp:Label ID="lblTitle" runat="server" Text="Dynamic Control in Master
Page Test: "/>
<p />
<asp:placeHolder ID="phPlaceHolder" runat="server"/>
<p />
<asp:Button ID="btnSubmit" runat="server" OnClick="btnSubmit_OnClick"
Text="Submit" />
<p />
<asp:Label ID="lblValue" runat="server" />


</asp:Content>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top