Is it possible to use the onclientclick
property of a button to do a clientside check. If the check returns true
, then fire the onclick
In the server page create the button:
var button1 = new Button();
button1.ServerClick += new EventHandler(button1_ServerClick);
button1.OnClientClick = SetJsForSaveBtn();
button1.Attributes.Add("UseSubmitBehavior", "false");
panel.Controls.Add(button1 );
//Contains the server code
private void saveBtn_ServerClick(object sender, EventArgs e)
{
//do something if ClientClick returns true
}
//Contains the JS code for the page
LiteralControl js = new LiteralControl();
panel.Controls.Add(js);
js.Text =@" ";
private string SetJsForSaveBtn()
{
var jsfunc = @" return CheckValidationOnClient()";
return jsfunc ;
}