setting html control property in javascript and page behind code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I have a div control on an aspx page. I toggle the display property between
'block' and 'none' client side using the following javascript:

function toggleDivOnOff(divID) {
var x = document.getElementById(divID)
x.style.display == 'block'? x.style.display='none' : x.style.display='block';
}

In the code behind page, I want to use the value of the display property to
decide on an action to be taken using the following:

if (mydiv.Attributes.CssStyle["display"] == "block")
{
//do something
}

However, it would seem that although I can alter the way the div is
displayed on the aspx page either via the javascript or using code behind (
e.g. mydiv.Attributes.CssStyle["display"] = "block";), the code behind seems
not to recognise changes made in the javascript . Is there a way of
referencing the display property in the code behind in such a way as to avoid
this problem?

Many thanks,

Pete
 
The properties of the DIV as set on the client side will not
automatically be sent back to the server by the ASP.NET page, as only
input fields (and viewstate) are sent, not properties of other objects
on the page.

I would probably store the visibility in a hidden INPUT field on your
form (perhaps neatest to do this in your FORM onsubmit event, if you
set the visibility from more than one location), and this can then be
checked from server-side code.
 

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

Back
Top