[web] ASP.net Client and Server Interaction

Started by
2 comments, last by Wan 18 years, 9 months ago
Hi, this question is sorta similar to "ASP game questions", but.. Right now I have a Server control button, that when clicked, it changes some things in a database..but I would also like to make it change a
tag's display style to 'none'. The only way I know this possible is with &#106avascript, but I can't add an OnClick Event to the Server Control to run a &#106avascript function..soo...I guess.. What are my options here? Maybe (somehow) changing the div tag's display to none, and then doing a page refresh? If this is my only option, how would i change the display style? Thanks again, kag1
Advertisement
You can set its style server side after the postback like this:
btnTest.style["display"] = "none";

Or you can do it immediately by adding an extra attribute in the page load (or where ever appropriate):
btnTest.Attributes["onclick"] = "this.style.display = 'none'";
hrmmm..

I'm trying to make everything inside the div tag display to be none. (i guess when you use the brackets it doesn't show up..as you cannot see that in my first post).

So say my layout is like this
<div id="blah" style="display:'block';"><asp:control1 runat=server><random html things><asp:button name="TestButton" runat=server OnClick="ButtonHandler"></div>protected void ButtonHandler(object sender, EventArgs e){// do some MS SQL Query}


What I want to do is when that button "TestButton" is pushed, I want it to do the MS SQL stuff...as well as change the div "blah" display style property to 'none'

From looking at your example..it looks like it would only change the button's display property to 'none'?

Or am I wrong?

but either way, thank you for your reply WanMaster
Quote:Original post by kag1
From looking at your example..it looks like it would only change the button's display property to 'none'?

Yes, I thought that was what you were trying to do.

Why don't you make the div a server control (HtmlGenericControl if I recall correctly, or use a panel)? Or place a server-side div inside the blah-div, if you don't want the div itself to disappear.
Then you just set the style-display property to "none", or you just make it invisible using the Visible property inside the TestButton click server event.

<div id="blah" style="display:'block';" runat="server"><asp:control1 runat=server><random html things><asp:button name="TestButton" runat=server OnClick="ButtonHandler"></div>protected System.Web.UI.HtmlControls.HtmlGenericControl blah;protected void ButtonHandler(object sender, EventArgs e){// do some MS SQL Query// make the div invisibleblah.Visible = false;// or set style.display to "none"blah.Style["display"] = "none";}

This topic is closed to new replies.

Advertisement