473,396 Members | 1,918 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Finding Value of Dynamic Control in MasterPage/ContentPage System

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("phPlace Holder").FindControl("txtbxTextBox")
'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>

Mar 15 '06 #1
2 7657
Using a masterpage prepends a string onto the front of your control
names, usually something like "ctl00_<contentplaceholdername>_".
(replacing <contentplaceholdername> with the name of the
ContentPlaceHolder the control was created in.
You would then use FindControl("ctl00_whatever_yourcontrolname").
I have no idea why this is, it drove me nuts for a while.
Hope this helps.

Simon

Mar 15 '06 #2
Oops, I realized this morning that the page I was having that problem
in had never been run so I didn't realize that i was talking out of my
ass since that solution doesn't work.
What ended up working was first getting the ContentPlaceHolder control
and then using findcontrol from there:
ContentPlaceHolder mainContent;
mainContent = (ContentPlaceHolder)Master.FindControl("MainFormHo lder");

DropDownList ddl =
(DropDownList)mainContent.FindControl("controlname ");

That one ought to work for you, sorry about the idiocy :)
Simon

Mar 16 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: phil1bruening | last post by:
Hi, How can I change webcontrols from a contentpage in the masterpage?
9
by: Leffe Andersson | last post by:
Hi folks! I have a MasterPage with some public methods, and I would like to call them from a (app_code) class. Is it possible to set a directive or an assembly reference to a MasterPage from a...
9
by: User | last post by:
OK, I asked in a reply, but I've wasted far too long so I'm going to put a new post out there in hopes that it will be more visible. I have a MasterPage. I want to call a method declared in that...
0
by: dawg1998 | last post by:
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...
5
by: jeffmagill | last post by:
Is it possible? I haven't been able to find any information about this. Not on the web, not in books. Is it possible to call a function or subroutine which is defined in a MasterPage from it's...
2
by: Alex Maghen | last post by:
I want to create a utility function that will seach the current page for one of my UserControls by it's type. So, let's say that I have a UserControl whose class I defined as follows: namespace...
5
by: Dinu | last post by:
How to Cast a Variable to User control in ASP.NET using vb.net as code- behind
1
by: =?Utf-8?B?Sm9obg==?= | last post by:
I have a dropdownlist in masterpage and a big table in contentpage. When ddl selection changes, I want to move a specific row of the table to the top of the contentpage. Can I do something like <a...
2
by: Sully | last post by:
I know this is a basic question, but I cannot find the answer. I have a 3 LinkButtons on the masterpage that set a session variable, this session variable does not get relayed to the content page...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.