asp.net - How can I call eventhandler? -
void lbl_click(object sender, eventargs e) { linkbutton lnk = sender linkbutton; int currentpage = int.parse(lnk.text); int take = currentpage * 10; int skip = currentpage == 1 ? 0 : take - 10; fetchdata(take, skip); }
hi,
i want call method lbl_click() whenever click happens.
how can define aspx tag call function " lbl_click()" whenever click happens? or can use javascript invoke "lbl_click()" function?
code event handler lbl_click executed when click event fired link button. functionally, should happen when click paging link buttons.
try put breakpoint in lbl_click function , fire event clicking on paging link buttons in ui.
since, still not working you. have created small working page show how should be.
code behind
using system; using system.web.ui.webcontrols; public partial class default2 : system.web.ui.page { protected void page_init(object sender, eventargs e) { createdynamiclinkcontrols(); } private void createdynamiclinkcontrols() { (int = 0; < 10; i++) { linkbutton lk = new linkbutton(); lk.click += new eventhandler(lbl_click); lk.id = "lnkpage" + (i + 1).tostring(); lk.text = (i + 1).tostring() + " "; this.form1.controls.add(lk); } } void lbl_click(object sender, eventargs e) { linkbutton lnk = sender linkbutton; int currentpage = int.parse(lnk.text.substring(0, 1)); lbllinktext.text = currentpage.tostring(); } }
aspx page
<%@ page language="c#" autoeventwireup="true" codefile="default2.aspx.cs" inherits="default2" %> <!doctype html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> clicked : <asp:label runat="server" id="lbllinktext"></asp:label> </div> </form> </body> </html>
using code
try run page , link button appear on page, label placed on page displays page clicked.
Comments
Post a Comment