PC Review


Reply
Thread Tools Rate Thread

Control ID In Javascript

 
 
senfo
Guest
Posts: n/a
 
      26th Jan 2007
I'm having problems obtaining the client-side ID in my C# code. I've
tried to access it through the ID, UniqueID and ClientID properties, and
none of them show the entire ID.

The rendered HTML is always ctl00_PageContent_PlaceHolder_.... while
it's always just the plain ID on the server side.

Any ideas?

Thank you in advance,

--
Sean

website: http://senfo.blogspot.com
 
Reply With Quote
 
 
 
 
bruce barker
Guest
Posts: n/a
 
      26th Jan 2007
ClientID is the what the rendered id will be.


-- bruce (sqlwork.com)

senfo wrote:
> I'm having problems obtaining the client-side ID in my C# code. I've
> tried to access it through the ID, UniqueID and ClientID properties, and
> none of them show the entire ID.
>
> The rendered HTML is always ctl00_PageContent_PlaceHolder_.... while
> it's always just the plain ID on the server side.
>
> Any ideas?
>
> Thank you in advance,
>

 
Reply With Quote
 
Mark Rae
Guest
Posts: n/a
 
      26th Jan 2007
"senfo" <(E-Mail Removed)-WANT-NO-SPAM> wrote in message
news:(E-Mail Removed)...

> I'm having problems obtaining the client-side ID in my C# code. I've tried
> to access it through the ID, UniqueID and ClientID properties, and none of
> them show the entire ID.


If none of them shows the entire ID, what do they actually show...?

..ClientID should show the rendered ID of the control so that e.g. you could
reference it in client-side JavaScript with document.getElementById(...)

> The rendered HTML is always ctl00_PageContent_PlaceHolder_.... while it's
> always just the plain ID on the server side.


That's correct.

> Any ideas?


Not until you actually specify what the problem is...


 
Reply With Quote
 
senfo
Guest
Posts: n/a
 
      26th Jan 2007
Mark Rae wrote:
> "senfo" <(E-Mail Removed)-WANT-NO-SPAM> wrote in message
> news:(E-Mail Removed)...
>
>> I'm having problems obtaining the client-side ID in my C# code. I've tried
>> to access it through the ID, UniqueID and ClientID properties, and none of
>> them show the entire ID.

>
> If none of them shows the entire ID, what do they actually show...?


Given the following code, each label displays the text, "SomeValue".

MyControl.ID = "SomeValue";

Label1.Text = MyControl.ID;
Label2.Text = MyControl.UniqueID;
Label3.Text = MyControl.ClientID;

> .ClientID should show the rendered ID of the control so that e.g. you could
> reference it in client-side JavaScript with document.getElementById(...)
>
>> The rendered HTML is always ctl00_PageContent_PlaceHolder_.... while it's
>> always just the plain ID on the server side.

>
> That's correct.
>
>> Any ideas?

>
> Not until you actually specify what the problem is...


I except one of those properties to tell me what the *real* client-side
ID is, which is always ctl00_PageContent_PlaceHolder_....

This isn't good because I need it for a JavaScript function.

Example:

Image img = new Image();

img.ImageUrl = "img.png";
img.ID = "MyTest";
img.Attributes.Add("onclick", "MyFunction('" + img.ClientID + "');");

This renders as

<img id="ctl00_PageContent_PlaceHolder_MyTest" src="img.png"
onclick="MyFunction('MyTest');" />

Please note that if anything looks a little strange, it's probably
becaused I typed all of that by hand without Visual Studio.

Thank you again,

--
Sean

website: http://senfo.blogspot.com
 
Reply With Quote
 
senfo
Guest
Posts: n/a
 
      26th Jan 2007
senfo wrote:
> I'm having problems obtaining the client-side ID in my C# code. I've
> tried to access it through the ID, UniqueID and ClientID properties, and
> none of them show the entire ID.
>
> The rendered HTML is always ctl00_PageContent_PlaceHolder_.... while
> it's always just the plain ID on the server side.
>
> Any ideas?
>
> Thank you in advance,
>


By the way, it may be important to note that the problem I am
experiencing is in a custom web control that I'm writing.

--
Sean

website: http://senfo.blogspot.com
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Read Page Control Values from Javascript User Control =?Utf-8?B?Um95?= Microsoft ASP .NET 10 1st Nov 2006 10:14 PM
How to fire Javascript events from a .NET winforms user control back to Javascript in IE jonathan.beckett Microsoft Dot NET 0 13th Jul 2006 02:51 PM
ASP.NET control using Javascript kplkumar Microsoft ASP .NET 2 1st Jun 2006 04:28 PM
asp.net control and javascript Aaron Microsoft ASP .NET 2 1st Jun 2005 08:04 AM
asp.net control and javascript Aaron Microsoft Dot NET 2 1st Jun 2005 08:04 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:19 PM.