Client ID

S

SimonZ

In ASP.NET 1.0 all client ID's of controls run at server were the same as
the rendered ones on the client.

In ASP.NET 2.0 the client id of server control is different on server than
on the client.

Can I set the client ID of server control or I can only read it?

If not, the client script should be written in code behind file and that is
not so attractive.

Thanks,S
 
G

Guest

SimonZ,
All the controls in an ASP.NET page have a UniqueId property. This is what
the id looks like in the HTML source of the page.
You can set the ID of a server control either declaratively on the ASPX
page, or programmatically when it is created via code.

using the various RegisterClientScriptBlock and related methods to add
client script to a page is not a bad thing, its actually a good idea.
Peter
 
B

Bruce Barker

the UniqueID is the server side id, ClientID is the id rendered for html.
even in 1.0, the clientid might not match the id typed in the HTML (say it
was in a repeator), in v 2.0 there are more cases of it. you shoudl always
use ClientID.

one thing you can do is generate javascript local variables for the ids in
the codebehind.


RegisterClientScriptBlock("myIds",string.Format(@"<script>
var id1 = '{0}';
var id2 = '{1}' ;
</script>",myControl1.ClientId, myControl2.ClientId);



-- bruce (sqlwork.com)
 
S

SimonZ

Thank you Bruce.

I think I'll use your suggestion.
But still I have to repair a lot of client script code
(I'm rewriting asp.net1.0 application to asp.net2.0)

Peter - I don't know why it is a good idea to write client script in code
behind. I think that this should be a users choice.

Regards,Simon
 

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

Top