|
-
May 26th, 2006, 02:03 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] [02/03] Click Events Problem (Very Easy)
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.
-
May 26th, 2006, 02:35 AM
#2
Thread Starter
Hyperactive Member
Re: [02/03] Click Events Problem (Very Easy)
-
May 26th, 2006, 03:22 AM
#3
Thread Starter
Hyperactive Member
Re: [02/03] Click Events Problem (Very Easy)
Is there a property like IsClicked or something that gets the control that is clicked?
-
May 26th, 2006, 03:43 AM
#4
Re: [02/03] Click Events Problem (Very Easy)
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
-
May 26th, 2006, 03:57 AM
#5
Thread Starter
Hyperactive Member
Re: [02/03] Click Events Problem (Very Easy)
 Originally Posted by Fishcake
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.
What the equivalent of CommandArgument in a LinkButton?
-
May 26th, 2006, 04:05 AM
#6
Re: [02/03] Click Events Problem (Very Easy)
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
-
May 26th, 2006, 04:06 AM
#7
Re: [02/03] Click Events Problem (Very Easy)
Can you post the code what you have done so far?
Use [code] source code here[/code] tags when you post source code.
My Articles
-
May 26th, 2006, 04:25 AM
#8
Thread Starter
Hyperactive Member
Re: [02/03] Click Events Problem (Very Easy)
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
-
May 26th, 2006, 04:26 AM
#9
Thread Starter
Hyperactive Member
Re: [02/03] Click Events Problem (Very Easy)
 Originally Posted by Fishcake
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
Hmmm....
How do you call OnCommand in code?
Or how do you get "Command_Test" in code?
-
May 26th, 2006, 04:40 AM
#10
Re: [02/03] Click Events Problem (Very Easy)
VB Code:
a.Command += New CommandEventHandler(test)
-
May 26th, 2006, 04:56 AM
#11
Thread Starter
Hyperactive Member
Re: [02/03] Click Events Problem (Very Easy)
 Originally Posted by Fishcake
VB Code:
a.Command += New CommandEventHandler(test)
I don't have withevents declared and I can't use withevents.
I get an error message that I can't directly call a.Command
-
May 26th, 2006, 05:13 AM
#12
Re: [02/03] Click Events Problem (Very Easy)
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#
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";
}
I can't remember how to add event handlers in vb.net....something to do with AddressOf?
-
May 26th, 2006, 05:28 AM
#13
Thread Starter
Hyperactive Member
Re: [02/03] Click Events Problem (Very Easy)
 Originally Posted by Fishcake
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#
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";
}
I can't remember how to add event handlers in vb.net....something to do with AddressOf?
OH MY GOD!!!!!!!!!! THANK YOU THANK YOU THANK YOU!!!
I've been searching the whole day for this kind of solution.
I'M NOT WORTHY!!!!!!
-
May 26th, 2006, 05:34 AM
#14
Re: [RESOLVED] [02/03] Click Events Problem (Very Easy)
You're welcome. A response like that makes it all seem worthwhile
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|