Solved

ASP Button question

Posted on 2016-08-26
2
75 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 500 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
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

626 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