473,549 Members | 2,948 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Button.Visible = false ?

Why I was unable to hide the previous button in the following code ?
private void ButtonClick(Obj ect sender, System.EventArg s e)
{
Button button = (Button)sender;
Button previousButton = (Button)Session["previousButton "];

if( previousButton == null )
{
// keep the first button
previousButton = button;
Session["previousButton "] = previousButton;
}
else
{
// Hide both button
button.Visible = false;
previousButton. Visible = false; // E R R O R don't work
previousButton = null;
Session["previousButton "] = previousButton;
}
}

Thank's

Marc
Nov 17 '05 #1
1 3305
AW
You simply cannot store a button in the Session. Don't forget that when the
page will be posted back, a NEW button will be created for any button
control on the page; so if you save a button, and on the next postback set
it to invisible, it will no be the button that exists on the page generated
by the postback.

To solve this problem, I suggest that you store the control's ID in the
ViewState, and then use FindControl to find it.

Your code would look like this:
private void ButtonClick(Obj ect sender, System.EventArg s e)
{
Button button = (Button)sender;
Button previousButton = (Button)FindCon trol[(string)Session["previousButton "]];
if( previousButton == null )
{
// keep the first button
previousButton = button;
Session["previousButton "] = previousButton. ID;
}
else
{
// Hide both button
button.Visible = false;
previousButton. Visible = false;
}
}

--
To reply, remove a "l" before the @ sign.

Arnaud Weil - MCT, MCSD.Net, MCAD.Net
Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
5855
by: Tim | last post by:
I have one main form that I use to view data as well as add new records. When I click the add new record button, many of the form's controls that arn't needed get set to invisible. When I'm done entering the new record, I want to click on a command button that resets and requeries the form to the state it is in when it first opens. What...
3
6065
by: Zürcher See | last post by:
Someone has implemented a Datagrid Button for the Windows.Form?
4
2593
by: Arif Çimen | last post by:
Hi to everybody, I have chnged a button text in design mode. But After compiling and executing the program the text of the button do not change to new value. Any Ideas? Thaks for helps.
6
3850
by: Rod Snyder | last post by:
I'm trying to set up a page with an asp.net link button that would send a user to a certain page and on page load execute a specific stored procedure tied to the button on the previous page. The link would be in a nav area and be something like "update". It would send the user to the main page and execute the stored procedure associated with...
5
1919
by: Girish | last post by:
I have TWO submit buttons of type IMAGE on my asp form. This renders as <input type="image">. I need to be able to eble the ENTER button for both buttons. Yes, I know that for the input type image, the submit happens automatically to the server. Heres my problem: I have two event handlers for both these buttons as stated below: BUTTON...
4
3497
by: John Boy | last post by:
Hi, Can anyone help. This is really doing my nut in. 3 years ASP exp. and now doing .DOT which is a step in the wrong direction. Basically I am left with the code of a guy who has left. When I click a button on a pop-up window the javascript for that button click does a 'button.form.submit'. On the Server side there is a Button click...
5
5411
by: Wonder | last post by:
How can I create or use the msgobx to show a message without a default button. The user has explicity to click on the button, so the msgbox closes it. Thanks,
0
2369
by: DJOuk | last post by:
Posted this on Asp.Net, seems to be a hard problem, I still can't work it out I have a edit button, this works fine, until I add the code that prevents the edit button from being seen by users who did not post that ticket. I cannot understand why this is happening. I get an error on the button says 'object reference not set in instance of...
8
2595
by: evenlater | last post by:
I have an .accde file with custom ribbons and with "Allow Full Menus" set to False, but the Office Button menu still gives the user the ability to create a new Access database, or -- much worse -- open an existing one. My application is on a terminal server and I'm trying to plug all the holes so the user can't do anything but use my...
4
3715
by: SAL | last post by:
Hello, I'm working, basically my first, AJAX page and am having a few problems. One is that the Click event for a button I have in UpdatePanel1 is not getting called. I've tried with the button both inside and outside of the updatepanel and the event doesn't get called either way. What might I be missing here? Incidently, something else,...
0
7520
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7446
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7718
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7470
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7809
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5368
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3498
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1058
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
763
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.