Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

linkbutton control

Status
Not open for further replies.

raghu3

Programmer
Dec 19, 2005
96
US
I have a set of 6 linkbutton controls on a page : click of each will show a part of data on the page.
How can I know which linkbutton was clicked in post back?
my sample code:

<asp:LinkButton id="a1" runat="server" Text="Name" />
<asp:LinkButton id="a2" runat="server" Text="Address" />
<asp:LinkButton id="a3" runat="server" Text="Details" />

Page_Load() {

if (this.IsPostBack()){

// Based on the link button clicked
// populate the text Box
// how to find out which button was clicked ?
}
}

Thanks
 
Use the click of the linkbutton click event to exectue your code.

Jim
 
You need to create an event for the linkbutton...

onclick="a1_OnClick" in the HTML for the linkbuttons

Code:
    protected void a1_OnClick(object sender, EventArgs e)
    {
        TextBox txt = new TextBox();
        txt = (TextBox)this.LoginControls.FindControl("NameOfTextBox");
        txt.Text = "populate";
    }

Hope this helps...

Hope everyone is having a great day!

Thanks - Jennifer
 
As all the links point to similar functionality, I thought I can trap the sender in the page_load.
Makes my code more managable ...
 
Look up this link in VS Help:
ms-help://MS.VSCC.2003/MS.MSDNQTR.2006JAN.1033/cpref/html/frlrfSystemWebUIWebControlsLinkButtonClassCommandArgumentTopic.htm
 
I'd say the best option would be to create a function and add a Handles declaration for each control that needs to call it - that's a much simpler and neater way in my opinion.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
You could also call code passing the option outside of you linkbutton code.

Code:
protected void a1_OnClick(object sender, EventArgs e)
{
   CallCode("a1")
}

public void CallCode(string sWhichButton )
{
   //code needed...
}

Hope everyone is having a great day!

Thanks - Jennifer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top