I was excited when I first heard that the Button class now has a property called UseSubmitBehavior because I understood that it would change the <input type='submit'> tag to <input type='button'>. This is a useful form of the button available in HTML because
it does not post back. Instead, it lets you associate javascript code that fires in its onclick event. For example, if I have a checkboxlist with a Select All button that runs javascript to mark all checkboxes, I would use <input type='button'>. In ASP.NET
1.x, I had to use the HtmlControl for the button (<input type='button' runat=server>). In doing so, I lost some of the niceties of the Button control class, like easy style settings.
In ASP.NET 2.0, the Button class also offers the OnClientClick property where I can supply that javascript I need in this button. Sounds perfect, right?
Unfortunately, when UseSubmitBehavior is false, it always adds a javascript call to __doPostBack(). In otherwords, it's still demanding a post back. The documentation (http://msdn2.microsoft.com/library/0sts8ds5(en-us,vs.80).aspx)
discusses this in detail. But I really don't understand their point. They write:
The point its making is that you can call GetPostBackEventReference and use the string it returns in some client-side code you write. What does that have to do with the button itself? You could always call GetPostBackEventReference for use in your own code.
In fact, that's exactly the reason GetPostBackEventReference exists.
I would like to know the value of adding a call to __doPostBack() here. I'm hoping there is no good reason and with a bug report to MS, they can remove the call to __doPostBack and let this become the HTML tag it was intended to be. Of course, if there is a
good reason, at least we'll benefit from getting the documentation clarified.
--- Peter Blum
Creator of Peter's Data Entry Suite (formerly Professional Validation And More and Peter's Date Package) and Peter's Polling Package
www.PeterBlum.com
UseSubmitBehiour="true" i.e., <input type = "submit"> ,
Here I am using the Default Behavior of Browser to post
the Form to server
Because I am not wants to use a __doPostBack function with this
Button for security reason because a Malicious User
can call the __doPostBack function to call the
Server Side Button Event,
Here the server side Event is executing from text changed
of a Textbox, calling Server Side Button which is disabled,
1) Why ASP.NET execute an Event coming which uses
__EVENTTARGET and the Button is not using this Behaviour?
2) Further for a Button which is disabledfrom Server Side,
Is EventValidate Method calling this event as Valid PostBack?
However for an Button Visible="False"
EventValidate Method calling this event as Invalid PostBack
"And whoever is removed away from the Fire and admitted to Paradise, he indeed is successful." (The Holy Quran)
Excellent Windows VPS Hosting Imran Baloch MVP, MVB, MCP, MCTS, MCPD
PLBlum
All-Star
30409 Points
5347 Posts
MVP
Button.UseSubmitBehavior=false comments
Jun 01, 2005 08:32 PM|LINK
In ASP.NET 2.0, the Button class also offers the OnClientClick property where I can supply that javascript I need in this button. Sounds perfect, right?
Unfortunately, when UseSubmitBehavior is false, it always adds a javascript call to __doPostBack(). In otherwords, it's still demanding a post back. The documentation (http://msdn2.microsoft.com/library/0sts8ds5(en-us,vs.80).aspx) discusses this in detail. But I really don't understand their point. They write:
The point its making is that you can call GetPostBackEventReference and use the string it returns in some client-side code you write. What does that have to do with the button itself? You could always call GetPostBackEventReference for use in your own code. In fact, that's exactly the reason GetPostBackEventReference exists.
I would like to know the value of adding a call to __doPostBack() here. I'm hoping there is no good reason and with a bug report to MS, they can remove the call to __doPostBack and let this become the HTML tag it was intended to be. Of course, if there is a good reason, at least we'll benefit from getting the documentation clarified.
Creator of Peter's Data Entry Suite (formerly Professional Validation And More and Peter's Date Package) and Peter's Polling Package
www.PeterBlum.com
Plucky
Member
731 Points
158 Posts
Re: Button.UseSubmitBehavior=false comments
Dec 12, 2005 08:02 PM|LINK
I would also like to hear clarification on this issue from microsoft.
Thanks.
skingpower
Member
6 Points
6 Posts
Re: Button.UseSubmitBehavior=false comments
Jul 16, 2007 04:57 PM|LINK
I will also like to know what is the reason behind it.
anjumrizwi
Member
26 Points
13 Posts
Re: Button.UseSubmitBehavior=false comments
Aug 28, 2007 07:20 AM|LINK
I would also like to hear clarification on this issue from microsoft.
Thanks.
Anjum Rizwi
kamii47
Star
9500 Points
2383 Posts
Re: Button.UseSubmitBehavior=false comments
Aug 31, 2007 12:44 PM|LINK
I am having problem with imagebutton as it doesn't have UseSubmitBehavior propert which i could set to false.
Now when ever I enter on the form my image button got submitted
(MCP,MCAD.net,MCSD.net,MCTS,MCPD.net[web])
jpbowman
Member
2 Points
1 Post
Re: Button.UseSubmitBehavior=false comments
Feb 12, 2009 06:55 PM|LINK
Here is a cheap but effective work around: short circuit the ;__doPostBack by putting two slashes (the javascript comment syntax):
<asp:button runat="server" ID="Button1" UseSubmitBehavior="false" text="My Sneaky Button" OnClientClick="MyLocalJavaScript()//" />The rendered control now reads
<input type="button" name="Button1" value="My Sneaky Button" onclick="MyLocalJavaScript()//;__doPostBack('Button1','')" id="Button1" />and the postback is commented out.
Of course, Microsoft will figure this out and find a way to prevent it later on ...
kamii47
Star
9500 Points
2383 Posts
Re: Button.UseSubmitBehavior=false comments
Feb 12, 2009 08:00 PM|LINK
(MCP,MCAD.net,MCSD.net,MCTS,MCPD.net[web])
shashankkale
Member
155 Points
77 Posts
Re: Button.UseSubmitBehavior=false comments
Feb 17, 2009 08:18 AM|LINK
You Tried IT.
kamii47
Star
9500 Points
2383 Posts
Re: Button.UseSubmitBehavior=false comments
Feb 20, 2009 06:11 AM|LINK
(MCP,MCAD.net,MCSD.net,MCTS,MCPD.net[web])
imran_ku07
All-Star
45864 Points
7713 Posts
MVP
Re: Button.UseSubmitBehavior=false comments
Feb 27, 2009 06:03 AM|LINK
One of the Comments that I see in,
UseSubmitBehiour="true" i.e., <input type = "submit"> ,
Here I am using the Default Behavior of Browser to post
the Form to server
Because I am not wants to use a __doPostBack function with this
Button for security reason because a Malicious User
can call the __doPostBack function to call the
Server Side Button Event,
<%@ Page EnableEventValidation="true" .....
<asp:TextBox ID="TextBox1" runat="server"
onchange="this.form.__EVENTTARGET.value='Button1';
this.form.submit();"></asp:TextBox>
<asp:Button Enabled="false" ID="Button1"
runat="server" Text="Buttonabc"
OnClick="Button1_Click" />
Here the server side Event is executing from text changed
of a Textbox, calling Server Side Button which is disabled,
1) Why ASP.NET execute an Event coming which uses
__EVENTTARGET and the Button is not using this Behaviour?
2) Further for a Button which is disabled from Server Side,
Is EventValidate Method calling this event as Valid PostBack?
However for an Button Visible="False"
EventValidate Method calling this event as Invalid PostBack
Excellent Windows VPS Hosting
Imran Baloch MVP, MVB, MCP, MCTS, MCPD