1

I have the following code which executes the C# onclick event.

<asp:LinkButton ID="LinkButton4" runat="server" onclick="LinkButton4_Click1">Apply Filter</asp:LinkButton>

I would also like to add a javascript onclick event to happen following this of

setVisible('cfilterpopup');

Basically I need it to store some information from the page when LinkButton4_Click1 happens and then setVisible sets an area of my page back to hidden because they entered that information and don't need to see it again.

What is the correct syntax to get both the C# onclick and the javascript onclick together. I'm looking for something like this but I know this is wrong

<asp:LinkButton ID="LinkButton4" runat="server" onclick="LinkButton4_Click1;setVisible('cfilterpopup')">Apply Filter</asp:LinkButton>
3
  • Which one do you want to trigger first, serverside or cilientsdie? Commented Jan 15, 2014 at 20:30
  • Server side first then client side preferably. Although for future knowledge I wouldn't mind knowing both ways. Commented Jan 15, 2014 at 20:39
  • Then I would suggest to use Page.ClientScript.RegisterStartupScript as shown in one answer. Commented Jan 15, 2014 at 20:42

1 Answer 1

1

you need to use onclient click

<asp:Button OnClientClick="String" />

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.onclientclick(v=vs.110).aspx

Sign up to request clarification or add additional context in comments.

2 Comments

<asp:LinkButton ID="LinkButton4" runat="server" onclick="LinkButton4_Click1" OnClientClick="setVisible('cfilterpopup')" /> is what I did. This works on my first page but gives a JavaScript runtime error: Unable to get property 'style' of undefined or null reference. They both use the same master.js that contains the javascript. Any ideas?
JavaScript error was because I left in the line of code from Sachin below. Once I removed it, everything worked fine.

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.