0

Possible Duplicate:
How to call javascript function from code-behind

I have an empty div that I want to be adding check boxes to if a code behind boolean is true.

Here is the div:

<div id="checkboxes" />

Here is my javascript function:

        <script type="text/javascript">
        function addCheckboxes() {
            alert("just an alert for now");
        }

And here is my code behind where I want to call the "addCheckboxes" function:

bool isMovingTask = Convert.ToBoolean(Request.QueryString["isMovingTask"].ToString());
        if (isMovingTask)
        {
            //call javascript function
        }
1
  • I heard something about client script but I had no idea what it is. I just realized after martin sent me the link how it works. However I guessed I could have looked up on msdn....But I wasn't too sure if there was anything else that needed to be added Commented Oct 12, 2012 at 15:29

2 Answers 2

2

See related answer here: How to call javascript function from code-behind

Basically you want to make a call to register your client script, there are a few ways to do this in .NET.

Sign up to request clarification or add additional context in comments.

Comments

1

javascript is called when server execution of code and finished and generated html/script response is sent to browser. You can access public property of code behind in javascript and use it.

Make a public property in code behind and assign value to it in code behind

Code Behind

public  bool isChecked = true;

Html

    function addCheckboxes() {

       if('<%= isChecked %>' == 'True')
       {
          //Your code here
          alert("just an alert for now");

       }
    }

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.