473,769 Members | 8,132 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.mast er"
title="Dynamic Control in Master Page" %>

<asp:Content ID="Content1" ContentPlaceHol derID="cphConte nt"
Runat="Server">

<script runat="server">

Sub Page_Load()

Dim txtbxTextBox As New TextBox()
txtbxTextBox.ID = "txtbxTextB ox"
phPlaceHolder.C ontrols.Add(txt bxTextBox)

End Sub

Sub btnSubmit_OnCli ck(ByVal sender As Object, ByVal e As
System.EventArg s)

Dim txtbxTextBox As New TextBox()

'// Neither of the two methods below finds the control
'txtbxTextBox =
Master.FindCont rol("frmForm"). FindControl("ph PlaceHolder").F indControl("txt bxTextBox")
'txtbxTextBox = CType(Master.Fi ndControl("frmF orm").FindContr ol
"phPlaceHolder" ).FindControl(" txtbxExample"), TextBox)

lblValue.Text = txtbxTextBox.Te xt
End Sub
</script>

<asp:Label ID="lblTitle" runat="server" Text="Dynamic Control in Master
Page Test: "/>
<p />
<asp:PlaceHolde r ID="phPlaceHold er" runat="server"/>
<p />
<asp:Button ID="btnSubmit" runat="server" OnClick="btnSub mit_OnClick"
Text="Submit" />
<p />
<asp:Label ID="lblValue" runat="server" />

</asp:Content>

Mar 15 '06 #1
2 7696
Using a masterpage prepends a string onto the front of your control
names, usually something like "ctl00_<content placeholdername >_".
(replacing <contentplaceho ldername> with the name of the
ContentPlaceHol der the control was created in.
You would then use FindControl("ct l00_whatever_yo urcontrolname") .
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 ContentPlaceHol der control
and then using findcontrol from there:
ContentPlaceHol der mainContent;
mainContent = (ContentPlaceHo lder)Master.Fin dControl("MainF ormHolder");

DropDownList ddl =
(DropDownList)m ainContent.Find Control("contro lname");

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
1188
by: phil1bruening | last post by:
Hi, How can I change webcontrols from a contentpage in the masterpage?
9
4350
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 normal class? I have no problem to call the masterpage's methods from a contentpage, but what I would like to do is someting like this... public partial class MyMaster : System.Web.UI.MasterPage
9
1915
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 class from a Page that uses the MasterPage. How do I do that? public partial class List : System.Web.UI.MasterPage { protected ArrayList m_SortList;
0
362
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 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
5
1856
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 derivative ContentPage? Thanks. Jeff
2
1653
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 MyUtils { public partial class SomeUserControl : System.Web.UI.UserControl { ... }
5
3266
by: Dinu | last post by:
How to Cast a Variable to User control in ASP.NET using vb.net as code- behind
1
1845
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 href="#mid"in ddl event handler? Maybe a Javascript? Please advise. Thanks.
2
1851
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 until there are 2 postbacks. MasterPage: protected void lbtn01_Click(object sender, EventArgs e) { Session = "01";
0
9579
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9414
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10197
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10032
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9848
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7391
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5293
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3947
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3549
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.