Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Apr 07, 2008 07:41 AM by Hua-Jun Li - MSFT
Member
249 Points
887 Posts
Apr 02, 2008 09:54 AM|LINK
Hello,
How do i prevent a form from being submitted twice ? Or more times, when submitted
In classic ASP i used to use a javascript disable button. But now, being new to .net I wonder if there are any methods preventing a double postback.
(This way i can have full control of what is being submitted)
thanks
Ehi
Participant
1117 Points
188 Posts
Apr 02, 2008 11:05 AM|LINK
Hi,
You can use the javascript ot disable the button as shown below.
<asp:Button ID="btnSubmit" runat="server" OnClientClick="Disable(this)" Text="Submit" OnClick="btnSubmit_Click" />
And in the javascript
function Disable(Obj) { Obj.disabled = true; }
Apr 02, 2008 11:13 AM|LINK
Thanks Rajganesh,
But you are not reading my post properly. I know about the javascript disable button. But am wondering if there are other ways.
Because i noticed if you do refresh the page, after submitting. It posts it twice.
Are there anyways in .net of guarding against submitting it twice ?
Thanks
Apr 02, 2008 11:26 AM|LINK
There is no default function available in .NET to detect the page refresh. But the below given link has an article which shows one of the way to achieve it. just check it.
http://www.dotnetspider.com/kb/Article4466.aspx
All-Star
75950 Points
5608 Posts
Apr 07, 2008 07:41 AM|LINK
Hi afrika,
Pease try the following method.
<asp:Button ID="Button1" runat="server" Height="38px" Text="Button" Width="143px" OnClick="Button1_Click" BorderStyle="Inset" />
Then you can add the code at Pgae_load to prevent the submit twince or more.
protected void Page_Load(object sender, EventArgs e) {
Button1.Attributes.Add("onclick", "this.disabled=false;"+this.GetPostBackEventReference(Button1));
}
Let me know if I have misunderstood what you mean. Thanks. Hope it helps, Hua Jun
afrika
Member
249 Points
887 Posts
prevent double postback
Apr 02, 2008 09:54 AM|LINK
Hello,
How do i prevent a form from being submitted twice ? Or more times, when submitted
In classic ASP i used to use a javascript disable button. But now, being new to .net I wonder if there are any methods preventing a double postback.
(This way i can have full control of what is being submitted)
thanks
Ehi
Rajganesh
Participant
1117 Points
188 Posts
Re: prevent double postback
Apr 02, 2008 11:05 AM|LINK
Hi,
You can use the javascript ot disable the button as shown below.
And in the javascript
function Disable(Obj) { Obj.disabled = true; }__________________________________________________
My Blog
If this post answers your question please mark it as Answered.
afrika
Member
249 Points
887 Posts
Re: prevent double postback
Apr 02, 2008 11:13 AM|LINK
Thanks Rajganesh,
But you are not reading my post properly. I know about the javascript disable button. But am wondering if there are other ways.
Because i noticed if you do refresh the page, after submitting. It posts it twice.
Are there anyways in .net of guarding against submitting it twice ?
Thanks
Rajganesh
Participant
1117 Points
188 Posts
Re: prevent double postback
Apr 02, 2008 11:26 AM|LINK
There is no default function available in .NET to detect the page refresh. But the below given link has an article which shows one of the way to achieve it. just check it.
http://www.dotnetspider.com/kb/Article4466.aspx
__________________________________________________
My Blog
If this post answers your question please mark it as Answered.
Hua-Jun Li -...
All-Star
75950 Points
5608 Posts
Re: prevent double postback
Apr 07, 2008 07:41 AM|LINK
Hi afrika,
Pease try the following method.
<asp:Button ID="Button1" runat="server" Height="38px" Text="Button" Width="143px" OnClick="Button1_Click" BorderStyle="Inset" />
Then you can add the code at Pgae_load to prevent the submit twince or more.
protected void Page_Load(object sender, EventArgs e)
{
Button1.Attributes.Add("onclick", "this.disabled=false;"+this.GetPostBackEventReference(Button1));
}
Let me know if I have misunderstood what you mean.
Thanks.
Hope it helps,
Hua Jun
If you have any feedback about my replies, please contact msdnmg@microsoft.com.
Microsoft One Code Framework