FindFullyQualifiedControlName with a MasterPage

S

sloan

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$DropDownList1"
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........................
 
M

Mark Rae

Is there a better way to do this?

<script type="text/javascript">

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

</script>
 

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,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top