473,386 Members | 1,791 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Button.Visible = false ?

Why I was unable to hide the previous button in the following code ?
private void ButtonClick(Object sender, System.EventArgs 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 3267
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(Object sender, System.EventArgs e)
{
Button button = (Button)sender;
Button previousButton = (Button)FindControl[(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
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...
3
by: Zürcher See | last post by:
Someone has implemented a Datagrid Button for the Windows.Form?
4
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
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...
5
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...
4
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...
5
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
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...
8
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 --...
4
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.