CodeVerge.Net Beta


   Item Entry   Register  Login  
Microsoft News
Asp.Net Forums
IBM Software
Borland Forums
Adobe Forums
Novell Forums




Can Reply:  No Members Can Edit: No Online: Yes
Zone: > Asp.Net Forum > visual_studio.visual_studio_2005 Tags:
Item Type: Date Entered: 6/1/2005 8:32:17 PM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
NR
XPoints: N/A Replies: 9 Views: 304 Favorited: 0 Favorite
10 Items, 1 Pages 1 |< << Go >> >|
"PLBlum" <>
NewsGroup User
Button.UseSubmitBehavior=false comments6/1/2005 8:32:17 PM

0

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:

When the System.Web.UI.WebControls.Button.UseSubmitBehavior property is false, control developers can use the System.Web.UI.Page.GetPostBackEventReference method to return the client postback event for the System.Web.UI.WebControls.Button. The string returned by the System.Web.UI.Page.GetPostBackEventReference method contains the text of the client-side function call and can be inserted into a client-side event handler.


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 Professional Validation And More Suite, Peter's Date Package, and Peter's Polling Package
www.PeterBlum.com
"Plucky" <>
NewsGroup User
Re: Button.UseSubmitBehavior=false comments12/12/2005 9:02:51 PM

0

I would also like to hear clarification on this issue from microsoft.

Thanks.

"skingpower" <>
NewsGroup User
Re: Button.UseSubmitBehavior=false comments7/16/2007 4:57:39 PM

0

I will also like to know what is the reason behind it.

"anjumrizwi" <>
NewsGroup User
Re: Button.UseSubmitBehavior=false comments8/28/2007 7:20:53 AM

0

I would also like to hear clarification on this issue from microsoft.

Thanks.

"kamii47" <>
NewsGroup User
Re: Button.UseSubmitBehavior=false comments8/31/2007 12:44:09 PM

0

 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 


Kamran Shahid (MCP,MCAD,MCSD.NET)
Sr. Software Engineer
Netprosys Inc.
www.netprosys.com
"jpbowman" <>
NewsGroup User
Re: Button.UseSubmitBehavior=false comments2/12/2009 7:55:52 PM

0

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" <>
NewsGroup User
Re: Button.UseSubmitBehavior=false comments2/12/2009 9:00:07 PM

0

Smart Work around

Kamran Shahid
Sr. Software Engineer
(MCP,MCAD.net,MCSD.net,MCTS,MCPD.net[web])
Netprosys Inc.
www.netprosys.com

Remember to click "Mark as Answer" on the post that helps U
"shashankkale"
NewsGroup User
Re: Button.UseSubmitBehavior=false comments2/17/2009 9:18:27 AM

0

You Tried IT.


Keep Walking...
"kamii47" <>
NewsGroup User
Re: Button.UseSubmitBehavior=false comments2/20/2009 7:11:42 AM

0

Yes I have in test application.

Kamran Shahid
Sr. Software Engineer
(MCP,MCAD.net,MCSD.net,MCTS,MCPD.net[web])
Netprosys Inc.
www.netprosys.com

Remember to click "Mark as Answer" on the post that helps U
"imran_ku07" <>
NewsGroup User
Re: Button.UseSubmitBehavior=false comments2/27/2009 7:03:08 AM

0

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

 

I will ask Peter, kamran and anyone, that what are the reasons.

 


We All move to our original place.
Don't forget.

Imran Baloch
10 Items, 1 Pages 1 |< << Go >> >|




   
  Privacy | Contact Us
All Times Are GMT