Nuno Gomes /* ASP.NET Adventures */

var myInterests = new { language : "C#", technology: "ASP.NET" };

ASP.NET Controls - System.Web.UI.HtmlControls.HtmlButton client click hits the server twice

Hi all,

At work we have about 5000 PC's that are mainly our commercial network. All those PC use intranet services and web applications.

Until a few months ago IE6 was our corporate browser (yep) but we ended moving to IE8.

A few days ago someone came to me saying that their application appears to have some problem because every time they click some HTML buttons the server gets two hits.

Also they are able to say that this didn't happen when they used the IE6.

In the faulty application the buttons that trigger two posts were System.Web.UI.HtmlControls.HtmlButton controls with Click event handlers registered.

After some research I found that the default type attribute value for HTML BUTTON element has changed in IE8 and later (here).

  • In IE7 and earlier the default value is 'button'
  • In IE8 and later the default value is 'submit'

This changed in browser default behavior was not reflected in the Server-Control that renders it: it doesn't set the type attribute value to button when a postback is required.

Without such change, every time we attached a Click event handler to a HtmlButton we endup with two posts: one triggered by the _doPostback function and another from the form itself (caused by the default type='submit' value.).

I easily bypass this problem by setting the type attribute value to 'button' in my base control.

Even so, I think that this change should be done by the framework itself when a postback is required in a HtmlButton.

After some 'reflection' I propose changing the System.Web.UI.Util.WriteOnClickAttribute method to do the job.

Such change would ensure the some behavior independent of the browser version.

If you have another workaround or you think I'm completely wrong please let me know.

Also if you think this is a real problem that should be solved then visit this Connect entry I create.

Posted: Oct 15 2010, 08:57 AM by nmgomes | with 14 comment(s)
Filed under:

Comments

Ali Khalid said:

Hi Nuno,

  I have seen this issue discussed in different forums and sites but this is the first time I have seen a proper dissection of this problem. Great post. Keep it up

# October 15, 2010 8:06 AM

nmgomes said:

Hi Wesley,

Yes ... I could do the same with a specific ControlAdapter.

BTW, I'm well aware about ControlAdapters. Take a look here.

# October 15, 2010 8:38 AM

AndrewSeven said:

This could possibly be fixed with a theme instead the control adapter?

# October 15, 2010 9:37 AM

nmgomes said:

Andrew,

As far as I remember type attribute cannot be changed using CSS. however, I can think about a skin file with (didn't try to see if it works). The only inconvenient I see is this requires all the effective submit buttons to have type="submit" set.

Again this wouldn't be a generic solution.

# October 15, 2010 10:04 AM

Learn to Speak Korean said:

"Nice put up! GA can be my biggest earning. Nonetheless, it’s not a much."

--------------------------------------------

my website is  

http://coffeecups.mobi

Also welcome you!

# November 23, 2010 9:59 AM

skateboard tech deck said:

"Hi there, I observe that your printed content is rather understanding because it talks about lots of interesting details. In Any Occasion, was wondering whether you would want to interchange web backlinks with my site, as I am searching to ascertain contacts to further amplify and gain ground for my word wide web portal. I don't mind you laying my word wide web back links in the primary page, just approving this links on this specific world-wide-web web page is more than enough. Anyway, would you be type sufficient message me back at my internet site if you might be eager in swapping inbound links, I would seriously value that. Thanks a great deal and I hope to hear from you shortly! "

--------------------------------------------

my website is <a href="zeroskateboards.org/.../birdhouse-birdhouse-complete-hawk-royal-787x316.html">royal skateboard trucks</a> .Also welcome you!

# December 4, 2010 9:24 AM

Rebounder Trampoline said:

Blogroll links aint that excellent :P but i'm not the admin… :P … Just Telling :P

--------------------------------------------

my website is  

harleydavidsonmotorcyclesblog.com

Also welcome you!

# December 6, 2010 3:51 PM

ipad app said:

-----------------------------------------------------------

"I usually do not post in Blogs but your weblog forced me to, incredible operate..<br> beautiful …"

# January 3, 2011 10:11 AM

best ipad stand said:

-----------------------------------------------------------

"Hi, I can’t recognize tips on how to increase your site in my rss reader. Are you able to Aid me, please"

# January 8, 2011 9:13 AM

dab radio reviews said:

Hello. Wonderful position. I didn't expect this on a Wednesday. This is a good story. Many thanks!

--------------------------------------------------------------------    

Celtic Languages and Literatures

# January 17, 2011 11:19 AM

Home Security Monitoring service said:

Thanks for sharing excellent informations. Your site is so cool. I'm impressed by the details that you've on this web site. It reveals how nicely you understand  this subject. Bookmarked this website page, will come back for extra articles. You, my friend, ROCK! I found simply the info I already searched all over the place and just couldn't come across. What a perfect web site.

<b><a href="http://franczyzy.pl/?p=83557

">Home Security Monitoring atlanta

<a/><b/>

# March 29, 2011 11:05 PM

Hershel Rabassa said:

Please let me know if you're searching for a writer for your blog. You've got some truly good articles and I think I could be a fantastic asset. In case you ever desire to take a number of the load off, I'd completely love to write some content for your blog in exchange for a link back to mine. Please shoot me an e-mail if interested.

# July 4, 2011 8:30 AM

hostgator black friday 2011 said:

Digital entire world isn't difference to help Black Friday. In fact Black Friday might be additional identified using the web compared to full price stores. Hostgator the main web host corporation on the earth is not an exception to it. Hostgator Black Friday ended up being the second many dug name upon Google throughout 2010. People gone crazy by using choosing ones own web hosting service plans. No small with provided 80% OFF cope for a confined moment after which you can 50% OFF full Black Friday.

You Can Check Out Hostgator Black Friday 2011 Hot Offer HERE

<a href=www.care2.com/.../3026464>hostgator black friday 2011</a>

# November 24, 2011 11:58 PM
Leave a Comment

(required) 

(required) 

(optional)

(required)