HighTechTalks DotNet Forums  

Script Control.value method

ASP.net Web Controls microsoft.public.dotnet.framework.aspnet.webcontrols


Discuss Script Control.value method in the ASP.net Web Controls forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
john
 
Posts: n/a

Default Script Control.value method - 11-02-2007 , 03:43 PM






I read that this method:



<script type="text/javascript" language="javascript">

alert($get('<%= CheckTxt.ClientID%>').value)

</script>



Can be used instead of:



alert(document.getElementById("TabContainer1_TabPa nel5_FormView8_CheckTxt").value)





But I receive a CheckTxt not Declared error, any suggestion as to how to
implement this?



Thanks

John



Reply With Quote
  #2  
Old   
Walter Wang [MSFT]
 
Posts: n/a

Default RE: Script Control.value method - 11-05-2007 , 12:13 AM






Hi John,

The purpose of using <%= CheckTxt.ClientID %> is to output a dynamic id of
the control CheckTxt at run-time. To make ASP.NET compiler recognize
CheckTxt, you must have a control with ID "CheckTxt" at the direct child
control hierarchy of current container (Page class or UserControl according
to the context).

If you're having other INamingContainer between this control and the root
container (for example, you're defining a control with id "CheckTxt" within
an ITemplate such as ItemTemplate), the compiler will not be able to refer
to the control directly using reference "CheckTxt".

You can use ClientScript.RegisterStartupScript or RegisterScriptBlock to
generate the javascript functions at run-time; at that time if you could
get a reference to a control (using FindControl), then you can use its
ClientID property to build the javascript.

Regards,
Walter Wang (wawang (AT) online (DOT) microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.


Reply With Quote
  #3  
Old   
john
 
Posts: n/a

Default Re: Script Control.value method - 11-05-2007 , 05:41 AM



Thanks, I was doing some experimenting and was thinking maybe it was just as
you stated, because if I just added a label control if found it no problem;
so it's the template that is at issue. I will study your other method to see
if I can learn it, I don't like having to rewrite my script with every
design change, so that would be a plus if I can do it your way.

John
""Walter Wang [MSFT]"" <wawang (AT) online (DOT) microsoft.com> wrote

Quote:
Hi John,

The purpose of using <%= CheckTxt.ClientID %> is to output a dynamic id of
the control CheckTxt at run-time. To make ASP.NET compiler recognize
CheckTxt, you must have a control with ID "CheckTxt" at the direct child
control hierarchy of current container (Page class or UserControl
according
to the context).

If you're having other INamingContainer between this control and the root
container (for example, you're defining a control with id "CheckTxt"
within
an ITemplate such as ItemTemplate), the compiler will not be able to refer
to the control directly using reference "CheckTxt".

You can use ClientScript.RegisterStartupScript or RegisterScriptBlock to
generate the javascript functions at run-time; at that time if you could
get a reference to a control (using FindControl), then you can use its
ClientID property to build the javascript.

Regards,
Walter Wang (wawang (AT) online (DOT) microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no
rights.




Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.