call a javascript function within code behind

Discussion in 'ASP .Net Web Controls' started by sajithkahawatta, Jun 20, 2007.

  1. 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
     
    sajithkahawatta, Jun 20, 2007
    #1
    1. Advertising

  2. 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.


    "sajithkahawatta" wrote:

    > 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
    >
    >
     
    Sriram Surapureddy, Jun 20, 2007
    #2
    1. Advertising

  3. thanx everyone for reply.
    dear David R. Longnecker i used your code and it is
    worked.
    thanx again
     
    sajithkahawatta, Jun 21, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ben Miller [msft]

    Re: Code Behind vs. no code behind: error

    Ben Miller [msft], Jun 27, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    620
    Alphonse Giambrone
    Jun 28, 2003
  2. Peri
    Replies:
    2
    Views:
    2,979
  3. Replies:
    5
    Views:
    25,605
  4. John

    Non-code behind to code behind

    John, Feb 19, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    509
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Feb 19, 2007
  5. verci
    Replies:
    4
    Views:
    1,924
    verci
    Apr 9, 2007
Loading...

Share This Page