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

VulpesRank #55 · 29.2K reputationPosted Dec 4, 2011, 10:28 AM EST
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
}
}
VulpesRank #55 · 29.2K reputationPosted Dec 4, 2011, 9:21 AM EST
aleksandar ruba33 reputationPosted Dec 4, 2011, 9:39 AM EST
if i understand this private bool pressed1 = false; I put in page load?
aleksandar ruba33 reputationPosted Dec 4, 2011, 10:24 AM EST
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
VulpesRank #55 · 29.2K reputationPosted Dec 4, 2011, 10:46 AM EST
Sam HobbsRank #107 · 20.5K reputationPosted Dec 4, 2011, 11:47 AM EST
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.
aleksandar ruba33 reputationPosted Dec 4, 2011, 10:26 PM EST