Link to home
Start Free TrialLog in
Avatar of SmashAndGrab

asked on

ASP Button question


I have this button.

<asp:Button ID="btnUpdate" OnClientClick="return Validate(this,;" class="btn btn-primary" runat="server" Text="Update" AutoPostBack="true" />

When the user clicks it - it runs a simple javascript.

function Validate(obj, objid) {

  // does some valiudation here then submits
        __doPostBack(objid, '');

Open in new window

My question is:    How do I get the button run my specific C# function after it has validated?
Avatar of Manoj Patil
Manoj Patil
Flag of India image

If OnClickClient has a return value of true then the codebehind OnClick event will fire. If OnClickClient is returned false then it won't.
If OnClickClient doesn't return anything the codebehind event will fire regardless. So you want..

<asp:Button runat="server" ID="btnConfirm" Text="Confirm" OnClick="btnConfirm_Click" />

<script language="javascript">
    function Validate() {
        return confirm('Save in db?');

Open in new window

protected void Page_Load(object sender, EventArgs e)
   // set OnClientClick 
   btnConfirm.OnClientClick = "return Validate();";

protected void btnConfirm_Click(object sender, EventArgs e)
    //save something in database

Open in new window

Above code reference is from below link
Avatar of Ramkisan Jagtap
Ramkisan Jagtap
Flag of Finland image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial