user1084319
user1084319

Reputation: 299

Calling javascript function from code behind to remove div, but divs appear when postback

I have 2 divs with asp control in them. When I want to perform a certain action I want the divs to appear, for the rest, I need them to hide.

In my Page_load, I have this code to call the javascript function:

if (Request.QueryString["isMovingTask"] != null)
    {
        isMovingTask = Convert.ToBoolean(Request.QueryString["isMovingTask"].ToString());
    }
    if (!isMovingTask)
    {
        Page.ClientScript.RegisterStartupScript(GetType(),"Remove","removeDiv();",true);
    }

the isMovingTask is a bool value that gets sent from my action file("viewTask.aspx"). If it is true, it means I am asking to move a task so I need the divs displayed, otherwise hide them. So in the if statement I check to see if it is not true, then I want to hide the divs. So I call a JS function called "removeDiv()" which looks like:

<script type="text/javascript">
        function removeDiv() {
            $('#checkboxes').remove();
            $('#exhibitWarning').remove();
        }
    </script>

"viewTask.aspx" is my page that calls a "moveTemplate.aspx" file inside a fancybox, all this code is in the "moveTemplate.aspx" page. so the first time I launch it, everything works, the divs are hidden etc. But when I click on a radio button which causes a postback, it for some reason puts the divs back in.

any ideas as to why it does that?

Upvotes: 0

Views: 751

Answers (2)

lichessISbetter
lichessISbetter

Reputation: 17

One can use panel controls. Its easy to set their visible property to true or false and then your task shall be done.

Upvotes: 1

Ankush Jain
Ankush Jain

Reputation: 7069

you can use Panel controls instead. And can set their visible property to true or false.

Upvotes: 3

Related Questions