471,337 Members | 1,161 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,337 software developers and data experts.

setting html control property in javascript and page behind code

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
Dec 28 '05 #1
2 5106
pH
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.

Dec 28 '05 #2
many thanks pH. Your explanation isvery clear.

"pH" wrote:
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.

Dec 28 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Amir Eshterayeh | last post: by
8 posts views Thread by David Lozzi | last post: by
6 posts views Thread by WT | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.