Hi Guys!!!
How do I know which button fired the event button.
Let's say I have:
Button1
Button2
Button3
Their click events calls the TestClick Procedure.
How do I know if Button1 Called TestClick Procedure.
Thanks in advance.
Printable View
Hi Guys!!!
How do I know which button fired the event button.
Let's say I have:
Button1
Button2
Button3
Their click events calls the TestClick Procedure.
How do I know if Button1 Called TestClick Procedure.
Thanks in advance.
Nobody!!!!
Is there a property like IsClicked or something that gets the control that is clicked?
So you have 3 buttons that all call the same function and you want to know which button was clicked?
You can use the buttons CommandArgument attributes and then check this value to work out which button was clicked.
VB Code:
Private Sub Button_Command(ByVal sender As System.Object, ByVal e As CommandEventArgs) Dim test As String = e.CommandArgument() End Sub
Hmm... there is no CommandArgument in a LinkButton Control.Quote:
Originally Posted by Fishcake
What the equivalent of CommandArgument in a LinkButton?
All buttons (link button, image button etc....) have a CommandArgument.
Try copying and pasting this...
Code:<asp:LinkButton ID="btnLink" OnCommand="Command_Test" CommandArgument="1" Runat="server" text="Link Button"></asp:LinkButton>
VB Code:
Public Sub Command_Test(ByVal sender As System.Object, ByVal e As CommandEventArgs) Dim Test As String = e.CommandArgument End Sub
Can you post the code what you have done so far?
So far, I have this.
VB Code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here Dim c As New TextBox Automaton.CreateTable(Table1, 5, 5) Table1.Rows(0).Cells(0).Controls.Add(a) Table1.Rows(1).Cells(0).Controls.Add(b) Table1.Rows(0).Cells(1).Controls.Add(c) ViewState.Add("Test", c.Text) c.Text = viewstate.Item("Test") a.Text = "Test Link" b.Text = "B Link" a.CommandArgument = "1" End Sub Public Sub Test(ByVal sender As System.Object, ByVal e As CommandEventArgs) Dim d As String d = e.CommandArgument Response.Write("Yes!!!") End Sub
Hmmm....Quote:
Originally Posted by Fishcake
How do you call OnCommand in code?
Or how do you get "Command_Test" in code?
VB Code:
a.Command += New CommandEventHandler(test)
I don't have withevents declared and I can't use withevents.Quote:
Originally Posted by Fishcake
I get an error message that I can't directly call a.Command
Sorry, I've been working in C# and converting it from memory (although looking back I'm not sure why I thought you were using vb in the first place).
Here's what i do in C#I can't remember how to add event handlers in vb.net....something to do with AddressOf?Code:protected void Page_Load(object sender, EventArgs e)
{
LinkButton a = new LinkButton();
a.Command += new CommandEventHandler(TestCommand);
a.Text = "Click Me";
this.plhTest.Controls.Add(a);
}
private void TestCommand(object sender, CommandEventArgs e)
{
this.lbltest.Text = "Test";
}
OH MY GOD!!!!!!!!!! THANK YOU THANK YOU THANK YOU!!!Quote:
Originally Posted by Fishcake
I've been searching the whole day for this kind of solution.
I'M NOT WORTHY!!!!!!
:afrog: :afrog: :afrog:
You're welcome. A response like that makes it all seem worthwhile :)