Popular Articles
Last viewed:
- C# Download File with Progress Bar
- ObjectDataSource TypeName with Constructor Parameters
- Windows Server 2003 Configure RRAS (Routing and Remote Access Service) Site to Site VPN
- Disable Button on Submit (Prevent multiple submits)
- ASP.NET Charting Control 3.5 fix for "Error executing child request for ChartImg.axd"
- ASP.NET CSS Highlight TextBox on Focus
Recent comments
- jkll
13 hours 28 min ago - Thank You
1 day 13 hours ago - Another approach
3 days 14 hours ago - Issue
4 days 3 hours ago - thanks
4 days 14 hours ago - Calendar date time
4 days 20 hours ago - Nice Explanation
5 days 11 min ago - ramya
1 week 21 hours ago - thank a lot
1 week 1 day ago - Very useful, but...
1 week 4 days ago

Now working with ValidationGroups
Right, I've now got this working with ValidationGroups by passing the group name to the Page_ClientValidate() method like this: Page_ClientValidate('validationgroup')
If like me you are registering the client script server side using ClientScript.RegisterClientScriptBlock(), you will need to register a separate script for each validation group. This caught me out at first as I use a helper routine, calling it for each button that I wanted the "click once" functionality applied to. This helper registers the client script, but because the "key" parameter was the same each time, only the first one got registered (with whatever ValidationGroup happened to be on that button). I got around this by including the ValidationGroup name in the RegisterClientScriptBlock() "key" parameter, ensuring that a separate client script is registered for each validation group. My complete helper routine is as follows:-
public static void ForceSingleButtonClick(Page page, Button button)
{
const string StyleName = "disabled_button";
string scriptKey = "clickoncebtn" + button.ValidationGroup;
if (!page.ClientScript.IsClientScriptBlockRegistered(scriptKey))
{
// Register script (use both IE and FF class attribute names).
StringBuilder sb = new StringBuilder();
sb.Append(" function disableButtonOnClick(oButton)");
sb.Append(" {");
sb.Append(" if (typeof(Page_ClientValidate) == 'function') ");
sb.AppendFormat(" if (Page_ClientValidate('{0}') == false) return false; ", button.ValidationGroup);
sb.Append(" oButton.disabled = true; ");
sb.AppendFormat(" oButton.setAttribute('className', '{0}'); ", StyleName);
sb.AppendFormat(" oButton.setAttribute('class', '{0}');", StyleName);
sb.Append("}");
// Register a separate script for each validation group.
page.ClientScript.RegisterClientScriptBlock(
typeof(WebUtility),
scriptKey,
sb.ToString(),
true);
}
// Alter button click to call javascript before normal postback.
button.UseSubmitBehavior = false;
PostBackOptions options = new PostBackOptions(button);
button.OnClientClick =
"disableButtonOnClick(this); " +
page.ClientScript.GetPostBackEventReference(options) + "; return;";
}
Hope this helps someone! I would be interested to hear of any problems etc.
Andy (andrew.stephens@cheshire.gov.uk)