|
-
Jan 6th, 2010, 04:33 PM
#1
[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 
-
Jan 7th, 2010, 02:33 AM
#2
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
-
Jan 7th, 2010, 02:45 AM
#3
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 
-
Jan 7th, 2010, 02:48 AM
#4
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
-
Jan 7th, 2010, 02:56 AM
#5
Re: user control and ClientID
 Originally Posted by gep13
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 
-
Jan 7th, 2010, 03:02 AM
#6
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
-
Jan 7th, 2010, 03:19 AM
#7
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 
-
Jan 7th, 2010, 03:24 AM
#8
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
-
Jan 8th, 2010, 04:16 PM
#9
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 <asp ropDownList> 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.
-
Jan 9th, 2010, 05:42 AM
#10
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 
-
Jan 9th, 2010, 09:02 AM
#11
Re: user control and ClientID
That is what I was trying to get at, he just said it better
-
Jan 9th, 2010, 06:18 PM
#12
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 
-
Jan 10th, 2010, 02:35 PM
#13
Re: user control and ClientID
Hee hee, no probs.
Have you got this problem solved then? Remember to mark resolved if so.
Gary
-
Jan 10th, 2010, 02:57 PM
#14
Re: user control and ClientID
* 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|