Results 1 to 14 of 14

Thread: [RESOLVED] user control and ClientID

  1. #1

    Thread Starter
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    Resolved [RESOLVED] user control and ClientID

    Hi!

    i have user control, inside its code i gave it an ID of "ddlSelectCountry"

    when i this control in one of my site pages i set its id to "ddlGetCountry"

    when i use "Trace.Warn(GetCountry.ClientID)" i get:

    Code:
    ctl00_MainContent_ddlGetCountry
    but when i view the page source in my browser the dropdown id is really:
    Code:
    ctl00_MainContent_ddlGetCountry_ddlSelectCountry
    this is really annoying when you need to use javascript i had to use funky way to be able to use this control with JS, is there any normal way around it so i can use only the clientid method and not have to add "_ddlSelectCountry" after the ClientID method?
    * Rate It If you Like it

    __________________________________________________________________________________________

    "Programming is like sex: one mistake and you’re providing support for a lifetime."

    Get last SQL insert ID

  2. #2
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: user control and ClientID

    Hey,

    I don't mean to doubt you, but are you sure that this is the case? Can you show the ASPX markup that you are using, and also the html that is rendered to the client (don't need to see all of it, just the relevant sections.

    Gary

  3. #3

    Thread Starter
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    Re: user control and ClientID

    this code is from the trace section:

    Code:
    	ctl00_MainContent_ddlGetCountry	0.00318260220499212	0.000810

    this is how its rendered:

    Code:
       <select name="ctl00$MainContent$ddlGetCountry$ddlSelectCountry" id="ctl00_MainContent_ddlGetCountry_ddlSelectCountry">

    this is how i use it it in my default.aspx
    Code:
       <CO:SelectLanguage runat="server"
    								     ID="ddlSelectLanguage"
    								     AddSelectLanguage ="true"
    								     SetLanguageToSession="false"
    								     AutoPostBack="true"
    								     ShowFlag="true" />

    and this is how i set it in the asmx files
    Code:
      <asp:DropDownList ID="ddlSelectLanguage" runat="server">
                </asp:DropDownList>
    * Rate It If you Like it

    __________________________________________________________________________________________

    "Programming is like sex: one mistake and you’re providing support for a lifetime."

    Get last SQL insert ID

  4. #4
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: user control and ClientID

    Hey,

    Ok, I suspect this is a typo, but do you mean ascx, where you said asmx?

    You to clarify, you have a User Control, called "ddlSelectLanguage", and in it, you have a DropDownList called "ddlSelectLanguage", and what you get rendered to the client is something called "ctl00$MainContent$ddlGetCountry$ddlSelectCountry".

    Because that definitely doesn't make any sense.

    I suspect you have pasted the wrong code snippets.

    Am I right?

    Gary

  5. #5

    Thread Starter
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    Re: user control and ClientID

    Quote Originally Posted by gep13 View Post
    Hey,

    Ok, I suspect this is a typo, but do you mean ascx, where you said asmx?

    You to clarify, you have a User Control, called "ddlSelectLanguage", and in it, you have a DropDownList called "ddlSelectLanguage", and what you get rendered to the client is something called "ctl00$MainContent$ddlGetCountry$ddlSelectCountry".

    Because that definitely doesn't make any sense.

    I suspect you have pasted the wrong code snippets.

    Am I right?

    Gary
    yes i mean ascx sorry about that,

    but i don't i posted to wrong code,

    when i refresh the page and use the code in the page load event:
    Code:
    Trace.Warn(ddlGetCountry.ClientID);
    i get this in the trace information:
    Code:
    	ctl00_MainContent_ddlGetCountry	0.00318260220499212	0.000810
    then i right click on the browser (without refreshing)
    and in the source when i check the same control ID i get this as its ID:
    Code:
    ctl00_MainContent_ddlGetCountry_ddlSelectCountry
    so as use see the ID that i gave this ddl inside the ascx file is combined to the ID i gave the usecontrol in my website page in the html source
    but the client id don't show that therefore when passed to JS file this ID worth nothing.
    * Rate It If you Like it

    __________________________________________________________________________________________

    "Programming is like sex: one mistake and you’re providing support for a lifetime."

    Get last SQL insert ID

  6. #6
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: user control and ClientID

    Hey,

    Ok, hold on a second now. In post #3, you are talking about ddlSelectLanguage and now we have jumped back to ddlSelectCountry. So which one is it. I just want to clear up this part before we go any further.

    Gary

  7. #7

    Thread Starter
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    Re: user control and ClientID

    you are absolutely right, i have two of these control one is select language and the other is select country the problem is with the select country control,
    i can't get its ascx code right now cause i'm already at my office.
    * Rate It If you Like it

    __________________________________________________________________________________________

    "Programming is like sex: one mistake and you’re providing support for a lifetime."

    Get last SQL insert ID

  8. #8
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: user control and ClientID

    Ok, now that we have got that sorted out...

    Does that mean that you also have a user control for Select Language that is working, i.e. the clientid is what you expect, but the Select Country User Control is not working?

    Can you do a diff between them?

    From a high level, I can see why the ClientID is coming up the way it is when rendered to the page, i.e. Content Control $ User Control $ Drop Downlist, but I am at a loss to say why the trace command is showing what it is.

    Unless of course, you are actually doing a ClientID of the User Control, as it is difficult to tell from your naming convention. i.e. in post #3, you seem to have a UserControl called "ddlSelectLanguage" and then a DropDownList named "ddlSelectLanguage", which doesn't really make sense. You might want to name your user control something else.

    Gary

  9. #9
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: user control and ClientID

    Show the actual HTML source, not just snippets of it. Show the <select> as well as what it's inside.

    You're doing a .ClientID on a user control - and I think it's returning the right thing. It's a container and it may contain nothing but the DDL. I'd guess that you have an ASCX and the ASCX has nothing but an <aspropDownList> in it. So the ClientID of the ASCX is correct. But you're comparing it manually not to the ASCX but to the DDL. If you want to make the right comparison, you need to expose the DDL's ClientID and compare with that. You can make it a public property inside the ASCX.

    public string DDLClientID { get { return ddlSelectCountry.ClientID; } }

    Note that it's readonly.

  10. #10

    Thread Starter
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    Re: user control and ClientID

    dang, exposing the clinet id.. i forgot all about that... i will try that today.

    thanks!
    * Rate It If you Like it

    __________________________________________________________________________________________

    "Programming is like sex: one mistake and you’re providing support for a lifetime."

    Get last SQL insert ID

  11. #11
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: user control and ClientID

    That is what I was trying to get at, he just said it better

  12. #12

    Thread Starter
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    Re: user control and ClientID

    i know Gary, you showed me how to expose client id of user control in another thread i opened month ago.
    * Rate It If you Like it

    __________________________________________________________________________________________

    "Programming is like sex: one mistake and you’re providing support for a lifetime."

    Get last SQL insert ID

  13. #13
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: user control and ClientID

    Hee hee, no probs.

    Have you got this problem solved then? Remember to mark resolved if so.

    Gary

  14. #14

    Thread Starter
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    Re: user control and ClientID

    i always forget!:B
    * Rate It If you Like it

    __________________________________________________________________________________________

    "Programming is like sex: one mistake and you’re providing support for a lifetime."

    Get last SQL insert ID

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width