Hi Sue,
Thanks for your response. As for the problem you metioned that the html
element's display property you set in the clientside script will return
back to original value. I think this is because some of the button or other
control called a postback event, so the page is rendered again from the
server, all the html control's attribute is set back to the original value.
Since you want to remain the control's state when set at client side, I
think generally in web page, we can use some hidden area to store some of
the html element's clientside state so that when posted back to the server,
we can retrieve these values and set those html elements' property in terms
of the client side state. For example, such an aspx page which has an
<span> element, set it as runat=server so that we can manipulate it at
serverside.
----------aspx page-----------
<HTML>
<HEAD>
<title>BehindPage</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="
http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
<script language="javascript">
function doDisplay(obj,state)
{
document.all.item(obj).style.display = state
document.all.item("hd" + obj).value = state
}
</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<span id="spanMain" runat="server">
<TABLE id="Table1" align="center" cellSpacing="1" cellPadding="1"
width="300" border="1">
<TR>
<TD>
<asp:Label id="Label1" runat="server">Label</asp:Label></TD>
<TD>
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox></TD>
<TD><FONT face="ËÎÌå">
<asp:Button id="Button1" runat="server"
Text="Button"></asp:Button></FONT></TD>
</TR>
<TR>
<TD><FONT face="ËÎÌå">
<asp:Label id="Label2" runat="server">Label</asp:Label></FONT></TD>
<TD><FONT face="ËÎÌå">
<asp:TextBox id="TextBox2" runat="server"></asp:TextBox></FONT></TD>
<TD>
<asp:Button id="Button2" runat="server"
Text="Button"></asp:Button></TD>
</TR>
<TR>
<TD>
<asp:Label id="Label3" runat="server">Label</asp:Label></TD>
<TD>
<asp:TextBox id="TextBox3" runat="server"></asp:TextBox></TD>
<TD>
<asp:Button id="Button4" runat="server"
Text="Button"></asp:Button></TD>
</TR>
</TABLE>
</span>
<table width="500" align="center">
<tr>
<td><input type="button" onclick="doDisplay('spanMain','none')"
value="HideSpan"> <input type="button"
onclick="doDisplay('spanMain','inline')" value="ShowSpan" id="Button3"
name="Button3" runat="server">
<asp:Button id="btnServer" runat="server" Text="ServerSide
Button"></asp:Button>
<input type="hidden" id="hdspanMain" value="inline" runat="server">
</td>
</tr>
</table>
</form>
</body>
</HTML>
in its code behind aspx.cs , we code the Page_Load event as this:
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if(hdspanMain.Value.Equals("none"))
{
spanMain.Attributes["style"] = "display:none";
}
else
{
spanMain.Attributes["style"] = "display:inline";
}
}
Thus, when the page is post back to server, we can check the hidden area's
value to determine how to set the html element's properties. Also, you can
extand the code according to your situation, the example just provided the
idea of maintaining the state between serverside postback.
Please try out the suggestion. If you have any question on it ,please feel
free to let me know.
Steven Cheng
Microsoft Online Support
Get Secure!
www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)