locked
how to call a code behind function on click event RRS feed

  • Question

  • User701853591 posted

    void lbl_Click(object sender, EventArgs e)
    {
    LinkButton lnk = sender as LinkButton;
    int currentPage = int.Parse(lnk.Text);
    int take = currentPage * 10;
    int skip = currentPage == 1 ? 0 : take - 10;
    FetchData(take, skip);
    }

    Hi,

    I want to call the method lbl_Click() whenever the click happens.

    How can I define any aspx tag to call a function " lbl_Click()" whenever the click happens? or can I use javascript to invoke this  "lbl_Click()" function?

    Friday, July 24, 2015 8:51 AM

Answers

  • User61956409 posted

    Hi parth2015,

    How can I define any aspx tag to call a function " lbl_Click()" whenever the click happens? or can I use javascript to invoke this  "lbl_Click()" function?

    The following sample is for your reference.

    <div>
        <asp:LinkButton ID="lbl" runat="server" OnClick="lbl_Click">I'm a LinkButton</asp:LinkButton>
        &nbsp;
        <asp:Label ID="lbl1" runat="server" Text="FireLinkButtonClickEvent" onclick="myfunction()"></asp:Label>
        <br />
        <asp:Label ID="lblresult" runat="server" Text=""></asp:Label>
    </div> 
    
    <script>
        function myfunction() {
            document.getElementById('<%= lbl.ClientID %>').click();
        }
    </script> 
    
    protected void lbl_Click(object sender, EventArgs e)
    {
        lblresult.Text = "LinkButton is clicked!";
    }
    

    Best Regards,

    Fei Han




    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 27, 2015 1:38 AM