I am a beginner and would like some help.
I have 3 button and the action on the 4th depends who had been pressed before.
try to give me some suggestion
thanks in advance!!!
button4 on-click
if(button1 was pressed before)
{
do something
}
else if(button2 pressed before)
{
do something
}....
Loading
VulpesPosted Dec 4, 2011, 3:28 PM
If it's an ASP.NET application (as suggested by mention of Page_Load), then you'll have to do it differently.
This should work:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Session["pressed1"] = false;
Session["pressed2"] = false;
Session["pressed3"] = false;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Session["pressed1"] = true;
Session["pressed2"] = false;
Session["pressed3"] = false;
}
// similar code for other buttons
protected void Button4_Click(object sender, EventArgs e)
{
bool pressed1 = (bool)Session["pressed1"];
bool pressed2 = (bool)Session["pressed2"];
bool pressed3 = (bool)Session["pressed3"];
if (pressed1)
{
// do something;
}
else if (pressed2)
{
// do something
}
else if (pressed3)
{
// do something
}
else // no button was previously pressed
{
// do something else
}
}
aleksandar rubaPosted Dec 5, 2011, 3:26 AM
Sam HobbsPosted Dec 4, 2011, 4:47 PM
Also note that when asking questions it helps to make it clear that it is an ASP application. The best way to do that is to put the question in the C# Corner ASP .Net forum but if you were to state explicitly in your question that it is ASP then that will make it easier for everyone.
VulpesPosted Dec 4, 2011, 3:46 PM
aleksandar rubaPosted Dec 4, 2011, 3:24 PM
i put in web form and is very logic this but dont work.
if you have other sugestion i will be happy and thx for your engagement
aleksandar rubaPosted Dec 4, 2011, 2:39 PM
if i understand this private bool pressed1 = false; I put in page load?
VulpesPosted Dec 4, 2011, 2:21 PM