Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ASP Button question

Posted on 2016-08-26
2
Medium Priority
?
85 Views
Last Modified: 2016-08-31
Hi,


I have this button.

<asp:Button ID="btnUpdate" OnClientClick="return Validate(this, this.id);" 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?
0
Comment
Question by:SmashAndGrab
2 Comments
 
LVL 19

Expert Comment

by:Manoj Patil
ID: 41771489
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?');
    }
</script>

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
http://stackoverflow.com/questions/28760687/invoke-onclientclick-of-button-in-code-behind
0
 
LVL 12

Accepted Solution

by:
Ramkisan Jagtap earned 2000 total points
ID: 41771494
<asp:Button ID="btnUpdate" OnClientClick="return Validate(this, this.id);" class="btn btn-primary" runat="server" Text="Update" onclick="btnUpdate_Click"  />

Open in new window


 
 protected void btnUpdate_Click(object sender, EventArgs e)
 {

        }

Open in new window

0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

876 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question