Updated (9/2/2009): It appears that this is no longer an issue in the RadControls for ASP.NET AJAX Q2 2009 release. Read this post for a better solution to this problem.

An all too common situation us web developers face is the dreaded “double submit” issue.

Users, for some reason, love to double-click on every submit button you might create in your web application.  It’s like an impulse.  They MUST submit the record into the database twice.

Poor souls.  They just can’t help themselves.

There are a handful of ways to address this issue using javascript, SQL, and server-side code.

I wanted to use javascript because I felt it was the most “lightweight” way to handle this issue.

Plus, my submit button was nested inside of a FormView, that was nested inside of a ContentPanel, that was nested inside of a MasterPage.

Fun.

In any event, I created a javascript function to fire on the OnClientClick property of the submit button:

<asp:Button ID=”btnSubmit” runat=”server” Text=”Submit Assessment Form” ToolTip=”Submit the Assessment Form”

onclick=”btnSubmit_Click” OnClientClick=”DisableSubmit(this);” />

I then created a javascript function on the Masterpage:

<script type=”text/javascript”>

function DisableSubmit(buttonElement) {

document.getElementById(buttonElement.id).disabled = true;

}

</script>

Hmmmm, when I would click the button, nothing would happen.

So I put in an alert and discovered that the javascript would fire, but the button would not enter the “disabled” state.

Frustrating!

Long story longer, I discovered that this would not work if I was using the Telerik RadFormDecorator.

That’s because the RadFormDecorator renames the client id of each control that it skins.

Therefore, the javascript function DisableSubmit was receiving “ctl00_ContentPlaceHolder1_frmAssessment_btnSubmit”, but the actual id was “Skinnedctl00_ContentPlaceHolder1_frmAssessment_btnSubmit”.

The RadFormDecorator was placing “Skinned” at the front of the id.

So I amended the javascript function:

<script type=”text/javascript”>

function DisableSubmit(buttonElement) {

document.getElementById(‘Skinned’ + buttonElement.id).disabled = true;

}

</script>

Now, the button disables appropriately.  Yay me!

My wife and I sporting SWEET T-Shirts from Telerik (Thanks Emily!)
My wife and I sporting SWEET T-Shirts from Telerik (Thanks Emily!)

My wife and family are happy.  That’s because I’m home in time for dinner.

Thanks to the hard working folks at Telerik, I can get things DONE.

Most importantly, I don’t have to sacrifice my design or UI strategies!

Let’s face it.  A lot of us developers (especially in health care) work on projects by ourselves.

We may be on a team of developers, but with so many projects coming in, we take one under our wing and run with it.

It becomes our baby.  We feed it, love it, and one day we let it leave our protection; hoping it does what we told it to do.

Having to work under these conditions means that we have to be the developer, tester, AND designer.

And it seems to me, the cool design elements always come last.  After we’ve ran out of time.

“Gee, I would really like to have this form AJAX-ifed, but I just don’t have the time.”

“It would be really cool to bring some color and design elements to this GridView, but alas, it’s due next week.”

“I spent all my time getting this INFERNAL thing to work; I don’t have time to make it pretty!”

Well, I am more than happy to suggest a FANTASTIC set of ASP.NET tools from Telerik.  I can’t tell you how much I love these tools.

Having these controls is like having a team of developers enhancing every aspect of your development.

For instance, the RadFormDecorator will allow you (with one line of code) to format all of your buttons, radio buttons, text boxes, list boxes, drop down lists, etc. to a skin of your choice.  Allowing you to instantly change the look and feel of your pages.

The RadEditor, with spell check, gives you a robust text editor that will make your boss think you SLAVED over the design.

The RadMenu, RadTabStrip, and RadPanel give you intuitive navigation with very little coding.

And the RadGrid?  RadGrid, alone, is worth the money spent.

I could go on and on.

Do not hesitate.  Download the trial today!


© 2007 travislowdermilk.com | iKon Wordpress Theme by TextNData | Powered by Wordpress | rakCha web directory