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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

LinkButton OnClick Event - Calling Code from App_Code 2

Status
Not open for further replies.

jzelhart

Programmer
Feb 10, 2003
469
US
I have multiple pages that have LinkButtons that have the exact same code behind them. Is it possible to call/link code from a shared class like one in App_Code directory instead of the code behind page? I still need the code behind for the code that is different.

I have searched and can't find anything but I am still hoping.


Now:
onclick="LinkButtonPOSITION1_Click"

Would like something like:

onclick="ReusableFuncton.LinkButtonPOSITION1_Click"

Thanks in advance!


Hope everyone is having a great day!

Thanks - Jennifer
 
Yes, you can put the functionality you need in a class file, or you can create a sub/function in the codebehind, and have that sub/function called from the events you need.
 
jbenson001 - thanks I know how to call the code from the codebehind that calls the shared code. Is there a way to do it in the ASPX and if so what is the syntax.

Thanks!

Hope everyone is having a great day!

Thanks - Jennifer
 
Is there a way to do it in the ASPX and if so what is the syntax.
do you mean in the html portion of the page?
What code do you have now?
 
instantiate the class and assign it to the event handler.
Code:
public class LinkButtonHandler
{
   public DoSomething(object sender, EventArgs e)
   {
      //do something here;
   }
}
Code:
public MyPage : Page
{
   protected override void OnInit(EventArgs e)
   {
      MyLinkButton.Click += new LinkButtonHandler().DoSomething;
   }
}
not sure how (if possible) to do it in markup. i try to keep as much code out of markup and code behind as possible.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Thanks to both of you - I will try adding the handler in code. I just enter it as part of the control in the HTML normally.

<asp:linkbutton id="LinkButtonPOSITION1" runat="server" causesvalidation="false" commandname="IgnoreRowCommand" onclick="LinkButtonPOSITION1_Click" onclientclick="resetDirty();" text="1"></asp:linkbutton>

Stars to both of you...

My work has gotten so busy that I don't get to spend much time on this site but it is still my first search. There were a few years that I was on the MVP list... once upon a time.

Hope everyone is having a great day!

Thanks - Jennifer
 
it's based on the number of responses to questions you answer and stars you get(I believe)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top