Hi Guys,
I'm currently working on a project where I have multiply panels on my page but only one is showing at any one time by the use of the Visible property.
What I'm trying to do is have 2 buttons on the page one for previous and one for next, so when the user clicks next it displays the next panel and hides the current one.
What I would like to happen is when the user clicks the button the event handler can tell which panel is currently showing. With this information I can then in the C# code behind display the correct panel based on the Id of the current visible panel.
Can you guys please point me in the right direction I have tried google but not getting the answers I need.
many Thanks
Codey
3 Replies - 1873 Views - Last Post: 25 February 2013 - 09:27 AM
#1
Passing an ID value of an element to the On Click event
Posted 24 February 2013 - 01:33 PM
Replies To: Passing an ID value of an element to the On Click event
#2
Re: Passing an ID value of an element to the On Click event
Posted 24 February 2013 - 02:52 PM
In Javascript you would examine
but I don't use ASP.
document.getElementById("someid").style.visibility
// or
document.getElementById("someid").style.display
but I don't use ASP.
This post has been edited by andrewsw: 24 February 2013 - 03:02 PM
#3
Re: Passing an ID value of an element to the On Click event
Posted 24 February 2013 - 07:34 PM
You should just be able to check the Visible property in the Next or Previous click event.
Example:
You would pretty much do just the opposite for the PreviousButton click event. This is just one way you might could handle this scenario and it will most likely need to be tweaked for your specific purpose.
Example:
protected void NextButton_Click(object sender, EventArgs e)
{
if (Panel1.Visible)
{
Panel1.Visible = false;
Panel2.Visible = true;
Panel3.Visible = false;
// Enable the previous button now since we are past the first panel
PreviousButton.Enabled = true;
}
else if (Panel2.Visible)
{
Panel1.Visible = false;
Panel2.Visible = false;
Panel3.Visible = true;
// Disable the NextButton because you are on the last panel
NextButton.Enabled = false;
}
}
You would pretty much do just the opposite for the PreviousButton click event. This is just one way you might could handle this scenario and it will most likely need to be tweaked for your specific purpose.
#4
Re: Passing an ID value of an element to the On Click event
Posted 25 February 2013 - 09:27 AM
You can also get the ID by casting the Sender. I would say that the easiest way would be the way that Nakor said to do it, but if you have two different buttons that hit the same method, then using sender will make absolutely sure that it works the way you want it to.
So basically use a switch statement and pass in the ID from Sender casting it AS a button. (*Note: use as so that if Sender cannot be cast as a Button you will not get an object reference error when trying to call .ID)
Then have two void methods for navigating forward and backward and call them based off which button was pressed.
So basically use a switch statement and pass in the ID from Sender casting it AS a button. (*Note: use as so that if Sender cannot be cast as a Button you will not get an object reference error when trying to call .ID)
Then have two void methods for navigating forward and backward and call them based off which button was pressed.
switch((Sender as Button).ID)
{
Case Forward.ID:
.....
Case Backward.ID:
.....
default:
break;
}
This post has been edited by rgfirefly24: 25 February 2013 - 09:29 AM
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote






|