0

I have a normal image for delete and an Asp.Net button. If I click the image which is inside the javascript I need to make the Asp.Net button click and perform it's operation.

Is there any way to do that from the client side: Here is my normal Html button:

This is my Asp.Net button:

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

This is my code behind:

  Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
                //Do something//
  End Sub
4
  • why do you need both the buttons? can you remove asp button? and use any ajax library to call the server side code when HTML button is clicked? Commented Nov 10, 2011 at 18:21
  • I dont understand why you have two. Create the button in design view and double click it. It will generate the code for the button. Commented Nov 10, 2011 at 18:22
  • Actually I don't need an Html button and instead of that I use Image which I must use in javascript.And If I click that Image I make the buton automatically click and able to perform its operartion. Commented Nov 10, 2011 at 18:23
  • @javasocute I knew that it's creates a codebehind for the button but I have an image instead of button in the javascript and when t is clicked I need to make the Asp.Net button click. Commented Nov 10, 2011 at 18:25

3 Answers 3

1

Try this:

var btn = document.getElementById("<%=Button1.ClientID%>");
if (btn){
    btn.click();
}
Sign up to request clarification or add additional context in comments.

Comments

1

I'd try this:

<input type="button" id="mybutton" onclick="document.getElementById('<%= Button1.ClientID %>_input').click();">

Comments

1

I think the most proper way would be to do this:

In your code-behind:

Protected ReadOnly Property ButtonClickScript() As String
    Get
        Return Page.ClientScript.GetPostBackEventReference(Button1, "")
    End Get
End Property

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

End Sub

In aspx:

<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
<img onclick="<%=ButtonClickScript() %>" />

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.