3

I'm developing Custom search web part. enter image description here

In that web Part I'm querying list item on button click event. so for that I'm using ASP.net button control But I don't know how to call click event. Because I never use any asp control before in SharePoint.

4

I am pre-assuming that you are adding this in your user control or visual web part.

You can add button click event in various methods:

C#

Your HTML part:

<asp:Button id="Button1" Text="Click here for greeting..." OnClick="GreetingBtn_Click" runat="server"/>

In code behind file there is one method for click event:

protected void GreetingBtn_Click(Object sender,
                           EventArgs e)
    {
        // When the button is clicked,


        //You can do your logic here
    }

JavaScript

Your HTML part:

<asp:Button id="Button1" ClientIDMode="Static" Text="Click here for greeting..." onclientclick="btnOneClick" runat="server"/>

Your script code for click event:

<script type="text/javascript">
     function btnOneClick()
     {
         var updatedLabel = document.getElementById('<%=inputLbl.ClientID %>');
         updatedLabel.innerHTML = updatedLabel.innerHTML + "1";
         return false;
     }
</script>

JQuery

Your HTML part:

<asp:Button ID="btnSummary" runat="server" Text="Next" />

Your script code for click event:

<script type="text/javascript">
function pageLoad(sender, args)
{
     $("#<%=btnSummary.ClientID %>").click(function() 
    {
        alert("1");
    });
}
</script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.