Home All Groups Group Topic Archive Search About

Refering to <asp:> webcontrols

Author
29 Jul 2006 1:05 PM
henk
Hey,

Question, how can i create client-side javascript that refers to a asp.net
webcontrol. For example set the focus of a textbox lik this.

<asp: TextBox  ID="Textbox1" />

(client side)
<script javascript>
    Textbox1.focus();
</script>

this wont't work, couse the webcontrol textbox1 has a diferent ID in the
actualy create HTML output. How can i solve this problem..

Thanks.

Henk

Author
29 Jul 2006 2:04 PM
Ray Booysen
henk wrote:
Show quote
>    Hey,
>
> Question, how can i create client-side javascript that refers to a
> asp.net webcontrol. For example set the focus of a textbox lik this.
>
> <asp: TextBox  ID="Textbox1" />
>
> (client side)
> <script javascript>
>    Textbox1.focus();
> </script>
>
> this wont't work, couse the webcontrol textbox1 has a diferent ID in the
> actualy create HTML output. How can i solve this problem..
>
> Thanks.
>
> Henk
You can generate the javascript server side:

"<script type='text/javascript'>" + Textbox1.ClientID +
".focus();</script>";
Author
29 Jul 2006 2:38 PM
Dmitry Nechipor. [MCDBA]
Try this one:

document.getElementById("<%=TextBox1.ClientID%>").focus();


Show quote
"henk" <henkenbou***@versatel.nl> wrote in message news:7d8f$44cb5d10$52adce4b$20735@news.versatel.net...
>    Hey,
>
> Question, how can i create client-side javascript that refers to a asp.net
> webcontrol. For example set the focus of a textbox lik this.
>
> <asp: TextBox  ID="Textbox1" />
>
> (client side)
> <script javascript>
>    Textbox1.focus();
> </script>
>
> this wont't work, couse the webcontrol textbox1 has a diferent ID in the
> actualy create HTML output. How can i solve this problem..
>
> Thanks.
>
> Henk
>
Author
11 Sep 2006 12:04 PM
msnews
What I have done is insert some Javascript to set the value for the ID of
the control.  I start with this static Javascript.

var controlId;

function setControlId(id)
{
  controlId = id;
}

Then I use Page.ClientScript.RegisterClientScriptBlock to add this code...

string script = "setControlId('" + textbox1.ClientId + "');";

You can then have the client script wrapped automatically with the script
tags when it is registered.  Then you just use the value for the controlId
in the rest of your Javascript.

Brennan Stehling
http://brennan.offwhite.net/blog/

Show quote
"henk" <henkenbou***@versatel.nl> wrote in message
news:7d8f$44cb5d10$52adce4b$20735@news.versatel.net...
>    Hey,
>
> Question, how can i create client-side javascript that refers to a asp.net
> webcontrol. For example set the focus of a textbox lik this.
>
> <asp: TextBox  ID="Textbox1" />
>
> (client side)
> <script javascript>
>    Textbox1.focus();
> </script>
>
> this wont't work, couse the webcontrol textbox1 has a diferent ID in the
> actualy create HTML output. How can i solve this problem..
>
> Thanks.
>
> Henk

AddThis Social Bookmark Button