473,385 Members | 1,806 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,385 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 7656
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.