Sign in to follow this  
kag1

[web] ASP.net Client and Server Interaction

Recommended Posts

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 javascript, but I can't add an OnClick Event to the Server Control to run a javascript 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

Share this post


Link to post
Share on other sites
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'";

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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 invisible
blah.Visible = false;
// or set style.display to "none"
blah.Style["display"] = "none";
}


Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this