Popular Articles
Last viewed:
- Tutorial for Configuring Silverlight 4, Entity Framework and WCF RIA Services in Separate Component Assemblies (DLL’s)
- Microsoft Word Spell Checker Doesn't Check Cut and Pasted Text
- Checking if Browser Supports Cookies (ASP.NET)
- Clustered Index vs. Non-Clustered Index in SQL Server
- Fix for Visual Studio 2008 SP1 Design Mode Error - [text] could not be set on [property]
- Get Index Fragmentation Percentage for all Tables in SQL Server Database
Recent comments
- Aha! Problems with UpdatePanel? Sorted ...
1 day 1 hour ago - Some help required with this
1 day 6 hours ago - Never seen this issue
1 week 1 day ago - Error in query.ToList()
1 week 1 day ago - Thanks
1 week 2 days ago - Thanks
1 week 5 days ago - To get the data working,
2 weeks 1 day ago - If I manually change the
2 weeks 1 day ago - Handling EDM Relationship Metadata
2 weeks 1 day ago - About the itextsharp version
2 weeks 1 day 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)