Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Script Control.value method

Reply
Thread Tools

Script Control.value method

 
 
john
Guest
Posts: n/a
 
      11-02-2007
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
 
 
 
 
Walter Wang [MSFT]
Guest
Posts: n/a
 
      11-05-2007
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 ((E-Mail Removed), 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
 
 
 
 
john
Guest
Posts: n/a
 
      11-05-2007
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]"" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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 ((E-Mail Removed), 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

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
How to execute a script from another script and other script does notdo busy wait. Rajat Python 3 01-08-2010 02:05 PM
RE: How to execute a script from another script and other script doesnotdo busy wait. VYAS ASHISH M-NTB837 Python 2 01-07-2010 08:18 PM
method def in method vs method def in block Kyung won Cheon Ruby 0 11-21-2008 08:48 AM
invoke a method by reflection£¨the method's parameters can not be ArrayList? jerry051 ASP .Net 2 08-02-2005 10:35 AM
ASP.NET: BC30289: Statement cannot appear within a method body. End of method assumed. Mike Wilmot ASP .Net 0 12-15-2003 07:49 PM



Advertisments