473,326 Members | 2,255 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,326 software developers and data experts.

FindFullyQualifiedControlName with a MasterPage


Ok.

In a simple scenario where I have a

MasterPage
Web Content Page (using the just mentioned MasterPage)
and a DropDownList on the content page.

When the page renders, I get something like this:

<select name="ctl00$Master1ContentPlaceHolder1$DropDownLis t1"
id="ctl00_Master1ContentPlaceHolder1_DropDownList1 ">
<option value="1">PickMe1</option>
<option value="2">PickMe2</option>
<option value="3">PickMe3</option>

</select>


And when I don't use a master page, I get something like this:

<select name="DropDownList1" id="DropDownList1">
<option value="1">PickMe1</option>
<option value="2">PickMe2</option>
<option value="3">PickMe3</option>

</select>

I've been trying to move some 1.1 code up to 2.0, and I had to some up with
something to work with MasterPages.
I have some custom javascript creation code, and I'm trying to get
"what the rendered name will be"
code put together.
This is what I got so far, though I think I'm missing something:

/////////////// START
private string FindFullyQualifiedControlName(Control c, MasterPage mp)

{

string returnValue = string.Empty;

if (null != mp)
{
if (null != c.NamingContainer)

{
Control nc = c.NamingContainer;
returnValue = nc.ClientID + "_";

}

}

returnValue += c.ID;

return returnValue;

}

/////////////// END

(Yes, I know I shouldn't concat strings together with += .. and I should use
StringBuilder ...... )

Is there a better way to do this?

I have it working. But I'm thinking when I go to creating a Custom Web
Control, this isn't going to work.

Thanks........................


Mar 16 '07 #1
3 2059
"sloan" <sl***@ipass.netwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
Is there a better way to do this?
<script type="text/javascript">

function validateForm()
{
if(document.getElementById('<%=DropDownList1.Clien tID%>').value == "")
{
alert('DropDownList1 cannot be blank');
document.getElementById('<%=DropDownList1.ClientID %>').focus();
return false;
}
}

</script>
Mar 16 '07 #2

Duh...

Ok, I screwed that one up.

Thanks Mark, I got it now.

"Mark Rae" <ma**@markNOSPAMrae.comwrote in message
news:ub**************@TK2MSFTNGP02.phx.gbl...
"sloan" <sl***@ipass.netwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
Is there a better way to do this?

<script type="text/javascript">

function validateForm()
{
if(document.getElementById('<%=DropDownList1.Clien tID%>').value == "")
{
alert('DropDownList1 cannot be blank');
document.getElementById('<%=DropDownList1.ClientID %>').focus();
return false;
}
}

</script>


Mar 16 '07 #3
"sloan" <sl***@ipass.netwrote in message
news:ej****************@TK2MSFTNGP03.phx.gbl...
Duh...

Ok, I screwed that one up.

Thanks Mark, I got it now.
We've all been there, mate... :-)
Mar 16 '07 #4

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

Similar topics

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...
3
by: Alex Maghen | last post by:
Hi. I'm a little confused about the code that resides in the code-behind of a MasterPage and the code that resides in the code-behind of the actual pages that USE that MasterPage. I'm noticing,...
5
by: Islamegy® | last post by:
In my project i have two master page which i change dynamic in runtime.. The first one with 1 ContentPanel "onepanel.master", the second with 2 contentPanel"twopanel.master".. but when i switch...
4
by: cevans | last post by:
Is there a way to load a MasterPage programmatically? Not switch a page's masterpage but to create a MasterPage object that holds a given masterpage. So I know I can do: MasterPage master =...
2
by: ThunderMusic | last post by:
Hi, Maybe there is another way of doing this, but here's my problem... I have my web site where I have a master page to have a common layout and a common behavior on all my pages (that's what...
6
by: =?Utf-8?B?QmVuIFIu?= | last post by:
Hi, WHen I specify my master page in the page's @Page directive, no problems. However, when I put it ias an attribute in Web.config's page element, the designer fails. It just says "Error...
7
by: Bon | last post by:
Dear all I create a master page with image buttons on the left-hand side for navigation. When a user clicks the student button, the content (i.e. ContentPlaceholder) in masterpage will be...
2
by: Frank Milverckowitz | last post by:
Hi, New to .NET... question about Masterpages vs. using Frameset I'm using Visual Studio 2005 and notice that the generated pages are of DTD/Doctype that don't support framesets. To use...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.