call a javascript function within code behind

S

sajithkahawatta

i want to call a java script function from code behind.

in page1.aspx page i placed script'

<script language="javascript">
function SetSelected()
{
infoTextBox.select();
}
</script>

i want to highlight text in infotextbox in some cases. so i want to
call this function within code behind.(within if statment).
how can i call this function .i tried with RegisterClientScriptBlock()
but i could not do it .but i think it can be used. can u tell me how a
java script function is called.

thankx
 
S

Sriram Surapureddy

There are several ways to do it.One approach is add the javascript in hidden
field like this..
<asp:HiddenField ID="test" runat="server" />
<script type="text/javascript">
if(document.all["test"].value == "1")
{
//whtever the script
document.all["test"].value ="";
}
</script>

and in the if condition set the "test" field to 1.
Hope this helps.
 
S

sajithkahawatta

thanx everyone for reply.
dear David R. Longnecker i used your code and it is
worked.
thanx again
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top