Here, when user clicks on submit button, its first checks the validation part.
After passing it, the data gets posted & button gets disabled. After that
the button gets enabled for new submission. Also the text written in the textbox
gets changes dynamically.
For Custom Control, go to new project. Select Web Custom
Control & rename it to singleClickBtn.
A custom control for button is developed. Here is the
code snippet for it:-
public class singleClickBtn : Button
{
[Bindable(true)]
[Category("Appearance")]
[DefaultValue("")]
[Localizable(true)]
private string replaceTitleTo;
public string ReplaceTitleTo
{
get { return this.replaceTitleTo; }
set { this.replaceTitleTo = value; }
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
StringBuilder
script = new StringBuilder();
script.Append("if (typeof(Page_ClientValidate)
== 'function') { ");
script.Append("if (Page_ClientValidate() ==
false) { return false; }} ");
if (!String.IsNullOrEmpty(this.replaceTitleTo))
{
script.Append("this.value = '");
script.Append(this.replaceTitleTo);
script.Append("';");
}
script.Append("this.disabled = true;");
script.Append(this.Page.ClientScript.GetPostBackEventReference(this,String.Empty));
script.Append(";");
this.Attributes.Add("onclick",
script.ToString());
}
|