FindFullyQualifiedControlName with a MasterPage

Discussion in 'ASP .Net' started by sloan, Mar 16, 2007.

  1. sloan

    sloan Guest

    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........................
     
    sloan, Mar 16, 2007
    #1
    1. Advertising

  2. sloan

    Mark Rae Guest

    "sloan" <> wrote in message
    news:%...

    > 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>
     
    Mark Rae, Mar 16, 2007
    #2
    1. Advertising

  3. sloan

    sloan Guest

    Duh...

    Ok, I screwed that one up.

    Thanks Mark, I got it now.



    "Mark Rae" <> wrote in message
    news:ub$...
    > "sloan" <> wrote in message
    > news:%...
    >
    > > 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>
    >
    >
     
    sloan, Mar 16, 2007
    #3
  4. sloan

    Mark Rae Guest

    "sloan" <> wrote in message
    news:ej6dnL%...

    > Duh...
    >
    > Ok, I screwed that one up.
    >
    > Thanks Mark, I got it now.


    We've all been there, mate... :)
     
    Mark Rae, Mar 16, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?QWxleCBNYWdoZW4=?=

    MasterPage -> Page -> MasterPage Code Access

    =?Utf-8?B?QWxleCBNYWdoZW4=?=, Apr 10, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    7,922
    Steven Cheng[MSFT]
    Apr 14, 2006
  2. ThunderMusic
    Replies:
    2
    Views:
    463
    Gregory Gadow
    Sep 27, 2006
  3. Randy Smith
    Replies:
    9
    Views:
    450
    Mark Rae
    Apr 14, 2007
  4. mr t
    Replies:
    0
    Views:
    417
  5. Torben Laursen
    Replies:
    4
    Views:
    585
    clintonG
    Mar 15, 2008
Loading...

Share This Page