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
        }
Community
  • 1
  • 1
user1084319
  • 299
  • 3
  • 9
  • 27
  • 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 – user1084319 Oct 12 '12 at 15:29

2 Answers2

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.

Community
  • 1
  • 1
martinwnet
  • 571
  • 2
  • 4
  • 10
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");

       }
    }
Adil
  • 146,340
  • 25
  • 209
  • 204