 |
|
 |
Here is a method code that covers client side validations and CausedValidation property as well: public static void DisableDoubleClick(Button btn, string waitMessage) { btn.Attributes.Add("onclick", String.Format("javascript:{0}this.disabled=true;{1}{2}", btn.CausesValidation ? "if (!Page_ClientValidate()) return false;" : "", String.IsNullOrEmpty(waitMessage) ? "" : "this.value='" + waitMessage + "';", btn.Page.GetPostBackEventReference(btn) )); }
So you just need to call it: DisableDoubleClick(Button1, "Please wait...");
|
|
|
|
 |
|
 |
Hi all,
I am working on a web site in which i have a video and the text format of the video(Trancription).
I have a text box where a searching string can be type and when i click on the search button the perticular word in the text file get highlighted but as i press the search button my page gets referesh and video starts from starting but i don't want my video to start from startins every time i press the search button.....plz help...
Thanks
|
|
|
|
 |
|
 |
for .net 2.0...
Set the propety of UseSubmitBehavior="false" and then the onclientclick = "this.disabled=true; this.value = 'Please wait...';"
And you do not even have to change it back in the code behind.
Simple!
Dave
www.dashsql.com
www.dashsql.com
|
|
|
|
 |
|
 |
Thanks this works perfectly! And Easily!!!!
~Candi
|
|
|
|
 |
|
 |
Lovely! I can confirm it also works with the Wizard control!
|
|
|
|
 |
|
 |
<asp:Button ID="Enter" runat="server" UseSubmitBehavior="false" onclick="Enter_Click" Text="הכנס" onclientclick = "this.disabled=true; this.value = 'Please wait...';" ToolTip="הכנס שורה חדשה לבסיס המידע" /asp>; idon't understand it' i work with 2.0 version .
|
|
|
|
 |
|
 |
Hi,
When I use this, my button disables perfectly, but my data does not submit.
I was using "onclick="EnrollButton_Click"
I can seem to get that event called with any variation of:
onclientclick = "this.disabled=true;this.value = 'Please wait...';EnrollButton_Click; "
How can I call the event from in there?
|
|
|
|
 |
|
 |
Make sure you return true if you want to have your EnrollButton_click, like this...
onclientclick = "this.disabled=true;this.value = 'Please wait...';return true;"
When you return true, the EnrollButton_Click function will be called automatically.
I created a simple PleaseWaitButton javascript function that I use in all of my applications...
function PleaseWaitButton(obj,message)
{
if (typeof(Page_ClientValidate) == 'function')
{
if ( Page_ClientValidate() )
{
obj.disabled = true;
obj.value=message;
return true;
}
}
return false;
}
and in my code, I set it like this...
onclientclick = "PleaseWaitButton(this,'Please Wait...')";
Enjoy!
KeepMyMarbles.com
|
|
|
|
 |
|
|
 |
|
|
 |
|
 |
I was going mad with it until I found this...
Thanks!
|
|
|
|
 |
|
 |
I got this Button1.Attributes.Add("OnClick","return VerifyData();"); --function that check all fields ---
and when I put the your code It does not work, my question is ¿how could I do to use your code disable my submit button after my validate function returns true?...tnks Chris
argento
|
|
|
|
 |
|
 |
Button1.Attributes.Add("onclick","javascript:" +
Button1.ClientID + ".disabled=true;" +
this.GetPostBackEventReference(Button1));
Is missing a semicolon.
Should be:
Button1.Attributes.Add("onclick","javascript:" +
Button1.ClientID + ".disabled=true;" +
this.GetPostBackEventReference(Button1) + ";" );
|
|
|
|
 |
|
 |
Nope, doesn't need this unless you are adding something else (javascript) behind this. Of course this depends on your browser specification on javascript. Was this in response to a particular problem?
Chris Lasater
http://www.geocities.com/lasaterconsult
|
|
|
|
 |
|
 |
Yes, for IE 6.0, the page loaded with an error icon on the status bar.
The warning was:
"Error: ';' expected"
The code referred to is below:
<input type="submit" name="btnSubmit" value="OK" önclick="javascript:btnSubmit.disabled=true;__doPostBack('btnSubmit','')if (typeof(Page_ClientValidate) == 'function') Page_ClientValidate(); " language="javascript" id="btnSubmit" class="button" />
For other browsers, I did not get this warning.
Thank you.
|
|
|
|
 |
|
 |
Although this is a neat trick, as people have posted above and I have verified, the functionality does not seem to be working with validators on the page.
However, in ASP.NET 2.0, there is a Property of the Button OnClientClick which does exactly that.
So wait....
Nas
|
|
|
|
 |
|
 |
It can work with page validation in .NET 1.1 but you have to check for it. This is a very nice and clean way to keep a user from posting more than once. This is not a trick. It is a very good programming practice.
Here is the code to make it work. You will just need to create a button and name it btnSubmit or change this code to use your name.
if(!Page.IsPostBack)
{
System.Text.StringBuilder sbDisable = new System.Text.StringBuilder();
sbDisable.Append("if (typeof(Page_ClientValidate) == 'function') {");
sbDisable.Append("if (Page_ClientValidate() == false) {");
sbDisable.Append("return false;");
sbDisable.Append("}");
sbDisable.Append("}");
sbDisable.Append("this.value = 'Please wait...';");
sbDisable.Append("this.disabled = true;");
//sbDisable.Append("document.all.btnSubmit.disabled = true;");
sbDisable.Append(Page.GetPostBackEventReference(btnSubmit));
sbDisable.Append(";");
//GetPostBackEventReference obtains a reference to a client-side script function that causes the server to post back to the page.
btnSubmit.Attributes.Add("onclick", sbDisable.ToString());
}
Chance favors the prepared mind!
- Travis Dane
- Louis Pasteur
|
|
|
|
 |
|
 |
The previous gentlemen was a bit overzealous in his decimation of the article. It actually does work with validators, and works in ASP.NET 2.0, just as you said. Perhaps he did not set up all his validators correctly. I have just used this again in ASP.NET 2.0 and it works great, validators intact. And it is a recommended practice by Microsoft. See my ASP.NET 2.0 Code:
override protected void OnInit(EventArgs e)
{
PostBlogButton.Attributes.Add("onclick", "javascript:" +
PostBlogButton.ClientID + ".disabled=true;" +
Page.ClientScript.GetPostBackEventReference(PostBlogButton, PostBlogButton.ID.ToString()));
RemoveBlogButton.Attributes.Add("onclick", "javascript:" +
RemoveBlogButton.ClientID + ".disabled=true;" +
Page.ClientScript.GetPostBackEventReference(RemoveBlogButton, RemoveBlogButton.ID.ToString()));
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
this.PostBlogButton.Click +=
new System.EventHandler(this.PostBlogButton_Click);
this.RemoveBlogButton.Click +=
new System.EventHandler(this.RemoveBlogButton_Click);
.......
I always do this anyway, just as a precaution:
protected void PostBlogButton_Click(object sender, EventArgs e)
{
try
{
if (!Page.IsValid) return;
Chris Lasater
http://www.geocities.com/lasaterconsult
-- modified at 12:09 Wednesday 29th March, 2006
|
|
|
|
 |
|
 |
What I discovered is that in rare circumstances (in my case a user control, no server controls with autopostback=true, and a validator), when validation fails the page does not render the __doPostBack function thus causing a javascript error when you try to re-submit the form. I worked around this by adding:
Page.GetPostBackClientHyperlink(submitButton, string.Empty);
That forces the __doPostBack function to be rendered on every page load.
|
|
|
|
 |
|
 |
pls give me the code to separate between 2 date
the 2 date from textbox
thanks
mohammed
|
|
|
|
 |
|
|
 |
|
 |
Hi,
It is a nice trick.
But it seems to have trouble when input data verification is required, for the verification script is added.
|
|
|
|
 |
|
 |
Works nicely using Peter BLum's VAM to override and leave a page after negative verification has occured though. What were your specific problems?
Chris Lasater
http://www.geocities.com/lasaterconsult
|
|
|
|
 |
|
 |
Good post. I would probaably place the code in the page load event so as to not mess with any designer generated code. Also, it would be interesting to sub class the button control and add that code as part of its createchildcontrols method.
|
|
|
|
 |
|
 |
All good ideas. Thanks for the comment!
Chris Lasater
http://www.geocities.com/lasaterconsult
|
|
|
|
 |