hi
I am using Javascript to do my validation
This is so i can display a loading message after a form is submitted.
Now, currently i do so like this.
I have a button, textbox and label like so:
<asp:textbox id="tb" runat="server"/>
<asp:Button id="btn" runat="server" text="Submit" />
<asp:Label id="lbl" runat="server" />
I then have a javascript function like so:
function validate()
{
if(document.get ElementById('tb ').value == '')
{
document.getEle mentById('lbl') .innerHTML = "please fill in
textbox";
return false;
}
else
{
document.getEle mentById('lbl') .innerHTML = "Loading... ";
return true;
}
}
And i attach this to the button in the code behind like so:
btn.Attributes. Add("onclick", "JavaScript : return validate();");
now, this works perfectly.
but what i would like to do, is disable the button if the value returned is
true.
Like this:
else
{
document.getEle mentById('lbl') .innerHTML = "Loading... ";
document.getEle mentbyId('btn') .enables = false;
return true;
}
But when i try this, the form will not submit.
How can i achieve what i'm trying to do here?
Submit a form only if validated, and disable the button if so?
TIA
Grant 8 1208
Hrm, interesting. I was able to replicate this -- apparently if the
calling object gets disabled, the browser cancels any subsequent
actions once control leaves the validate() function.
I was able to work around this by explicitly calling the
"__doPostBack() " method in the validate() function -- making an
explicit call to this should be identical to the form itself being
posted (if you create a LinkButton control and look at the page source,
you'll see that ASP.NET just does the same thing -- the LinkButton's
"onclick" event makes an explicit call to __doPostBack(), with its ID
as the argument).
So try this (note you'll have to create this script from the
server-side -- i.e., in the Page.PreRender handler -- in order to get
the reference to the postback method):
StringBuilder sb = new StringBuilder() ;
sb.Append("<scr ipt language='javas cript'>\r\n");
sb.Append("func tion validate()\r\n" );
sb.Append("{\r\ n");
sb.Append(" if(document.get ElementById('tb ').value == '')\r\n");
sb.Append(" {\r\n");
sb.Append(" document.getEle mentById('lbl') .innerHTML = 'Try
again...';\r\n" );
sb.Append(" return false;\r\n");
sb.Append(" }\r\n");
sb.Append(" else\r\n");
sb.Append(" {\r\n");
sb.Append(" document.getEle mentById('lbl') .innerHTML =
'Loading...';\r \n");
sb.Append(" ");
sb.Append(this. GetPostBackEven tReference(btn) ; sb.Append(";\r\ n");
sb.Append(" return true;\r\n");
sb.Append(" }\r\n");
sb.Append("}\r\ n");
sb.Append("</script>\r\n");
this.RegisterCl ientScriptBlock ("_PageScripts" , sb.ToString());
btn.Attributes["onclick"] = "return validate();";
HTH,
Luke
Grant,
I have a free javascript component on my website (comes with all source
code) that has as one of its methods a disable submit script. The code
hasn't been updated for .net 2.0 yet, but it's an easy conversion from 1.1
to 2.0. I just haven't had time to do it yet. If you take that code and add
your javascript for displaying your message to it you'll have what you need.
Another nice feature of the script is that before it disables the submit
button it first calls the microsoft javascripts that handle page validation
so that the button won't be disabled if the page isn't valid.
If you have any questions about converting the script or adding your bit of
javascript for your load message to it feel free to email me.
You may see a demo of the script (#3) and download the entire component as a
..net 1.1 project from here: http://www.aboutfortunate.com?page=javascriptdemo
--
Sincerely,
S. Justin Gengo, MCP
Web Developer / Programmer www.aboutfortunate.com
"Out of chaos comes order."
Nietzsche
"Grant Merwitz" <gr***@workshar e.com> wrote in message
news:en******** ******@TK2MSFTN GP12.phx.gbl... hi
I am using Javascript to do my validation This is so i can display a loading message after a form is submitted.
Now, currently i do so like this.
I have a button, textbox and label like so:
<asp:textbox id="tb" runat="server"/> <asp:Button id="btn" runat="server" text="Submit" /> <asp:Label id="lbl" runat="server" />
I then have a javascript function like so:
function validate() { if(document.get ElementById('tb ').value == '') { document.getEle mentById('lbl') .innerHTML = "please fill in textbox"; return false; } else { document.getEle mentById('lbl') .innerHTML = "Loading... "; return true; } }
And i attach this to the button in the code behind like so:
btn.Attributes. Add("onclick", "JavaScript : return validate();");
now, this works perfectly. but what i would like to do, is disable the button if the value returned is true. Like this: else { document.getEle mentById('lbl') .innerHTML = "Loading... "; document.getEle mentbyId('btn') .enables = false; return true; }
But when i try this, the form will not submit. How can i achieve what i'm trying to do here?
Submit a form only if validated, and disable the button if so?
TIA
Grant
Postback is desired at that time so why not disable from the server in the
page_load?
"Grant Merwitz" <gr***@workshar e.com> schreef in bericht
news:en******** ******@TK2MSFTN GP12.phx.gbl... hi
I am using Javascript to do my validation This is so i can display a loading message after a form is submitted.
Now, currently i do so like this.
I have a button, textbox and label like so:
<asp:textbox id="tb" runat="server"/> <asp:Button id="btn" runat="server" text="Submit" /> <asp:Label id="lbl" runat="server" />
I then have a javascript function like so:
function validate() { if(document.get ElementById('tb ').value == '') { document.getEle mentById('lbl') .innerHTML = "please fill in textbox"; return false; } else { document.getEle mentById('lbl') .innerHTML = "Loading... "; return true; } }
And i attach this to the button in the code behind like so:
btn.Attributes. Add("onclick", "JavaScript : return validate();");
now, this works perfectly. but what i would like to do, is disable the button if the value returned is true. Like this: else { document.getEle mentById('lbl') .innerHTML = "Loading... "; document.getEle mentbyId('btn') .enables = false; return true; }
But when i try this, the form will not submit. How can i achieve what i'm trying to do here?
Submit a form only if validated, and disable the button if so?
TIA
Grant
Thanks this sounds like what i need.
I've used the form.submit before, but then everything has to be in the
page_load method.
This sounds like a smarter option!
Thanks!
"slagomite" <sl*******@gmai l.com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. . Hrm, interesting. I was able to replicate this -- apparently if the calling object gets disabled, the browser cancels any subsequent actions once control leaves the validate() function.
I was able to work around this by explicitly calling the "__doPostBack() " method in the validate() function -- making an explicit call to this should be identical to the form itself being posted (if you create a LinkButton control and look at the page source, you'll see that ASP.NET just does the same thing -- the LinkButton's "onclick" event makes an explicit call to __doPostBack(), with its ID as the argument).
So try this (note you'll have to create this script from the server-side -- i.e., in the Page.PreRender handler -- in order to get the reference to the postback method):
StringBuilder sb = new StringBuilder() ; sb.Append("<scr ipt language='javas cript'>\r\n"); sb.Append("func tion validate()\r\n" ); sb.Append("{\r\ n"); sb.Append(" if(document.get ElementById('tb ').value == '')\r\n"); sb.Append(" {\r\n"); sb.Append(" document.getEle mentById('lbl') .innerHTML = 'Try again...';\r\n" ); sb.Append(" return false;\r\n"); sb.Append(" }\r\n"); sb.Append(" else\r\n"); sb.Append(" {\r\n"); sb.Append(" document.getEle mentById('lbl') .innerHTML = 'Loading...';\r \n"); sb.Append(" "); sb.Append(this. GetPostBackEven tReference(btn) ; sb.Append(";\r\ n"); sb.Append(" return true;\r\n"); sb.Append(" }\r\n"); sb.Append("}\r\ n"); sb.Append("</script>\r\n"); this.RegisterCl ientScriptBlock ("_PageScripts" , sb.ToString()); btn.Attributes["onclick"] = "return validate();";
HTH, Luke
Thanks thats great.
Nice to see you giving back to the community, I strive to do so myself.
If only i could find the time between work, eat and sleep :)
This looks like what i need, i have downloaded it and will try integrate it
into my code
Thanks Again!
"S. Justin Gengo [MCP]" <justin@[no_spam_please]aboutfortunate. com> wrote in
message news:uA******** ******@TK2MSFTN GP10.phx.gbl... Grant,
I have a free javascript component on my website (comes with all source code) that has as one of its methods a disable submit script. The code hasn't been updated for .net 2.0 yet, but it's an easy conversion from 1.1 to 2.0. I just haven't had time to do it yet. If you take that code and add your javascript for displaying your message to it you'll have what you need. Another nice feature of the script is that before it disables the submit button it first calls the microsoft javascripts that handle page validation so that the button won't be disabled if the page isn't valid.
If you have any questions about converting the script or adding your bit of javascript for your load message to it feel free to email me.
You may see a demo of the script (#3) and download the entire component as a .net 1.1 project from here: http://www.aboutfortunate.com?page=javascriptdemo
-- Sincerely,
S. Justin Gengo, MCP Web Developer / Programmer
www.aboutfortunate.com
"Out of chaos comes order." Nietzsche "Grant Merwitz" <gr***@workshar e.com> wrote in message news:en******** ******@TK2MSFTN GP12.phx.gbl... hi
I am using Javascript to do my validation This is so i can display a loading message after a form is submitted.
Now, currently i do so like this.
I have a button, textbox and label like so:
<asp:textbox id="tb" runat="server"/> <asp:Button id="btn" runat="server" text="Submit" /> <asp:Label id="lbl" runat="server" />
I then have a javascript function like so:
function validate() { if(document.get ElementById('tb ').value == '') { document.getEle mentById('lbl') .innerHTML = "please fill in textbox"; return false; } else { document.getEle mentById('lbl') .innerHTML = "Loading... "; return true; } }
And i attach this to the button in the code behind like so:
btn.Attributes. Add("onclick", "JavaScript : return validate();");
now, this works perfectly. but what i would like to do, is disable the button if the value returned is true. Like this: else { document.getEle mentById('lbl') .innerHTML = "Loading... "; document.getEle mentbyId('btn') .enables = false; return true; }
But when i try this, the form will not submit. How can i achieve what i'm trying to do here?
Submit a form only if validated, and disable the button if so?
TIA
Grant
because the process takes a while to run, and that causes users to click the
submit button again.
Anyway, after the button is submitted, they are redirected to a success page
"Edwin Knoppert" <ne**@hellobasi c.com> wrote in message
news:43******** **************@ text.nova.plane t.nl... Postback is desired at that time so why not disable from the server in the page_load? "Grant Merwitz" <gr***@workshar e.com> schreef in bericht news:en******** ******@TK2MSFTN GP12.phx.gbl... hi
I am using Javascript to do my validation This is so i can display a loading message after a form is submitted.
Now, currently i do so like this.
I have a button, textbox and label like so:
<asp:textbox id="tb" runat="server"/> <asp:Button id="btn" runat="server" text="Submit" /> <asp:Label id="lbl" runat="server" />
I then have a javascript function like so:
function validate() { if(document.get ElementById('tb ').value == '') { document.getEle mentById('lbl') .innerHTML = "please fill in textbox"; return false; } else { document.getEle mentById('lbl') .innerHTML = "Loading... "; return true; } }
And i attach this to the button in the code behind like so:
btn.Attributes. Add("onclick", "JavaScript : return validate();");
now, this works perfectly. but what i would like to do, is disable the button if the value returned is true. Like this: else { document.getEle mentById('lbl') .innerHTML = "Loading... "; document.getEle mentbyId('btn') .enables = false; return true; }
But when i try this, the form will not submit. How can i achieve what i'm trying to do here?
Submit a form only if validated, and disable the button if so?
TIA
Grant
Grant,
You're Welcome.
You get to sleep huh? Lucky dog.
--
Sincerely,
S. Justin Gengo, MCP
Web Developer / Programmer www.aboutfortunate.com
"Out of chaos comes order."
Nietzsche
"Grant Merwitz" <gr***@workshar e.com> wrote in message
news:u7******** ******@tk2msftn gp13.phx.gbl... Thanks thats great.
Nice to see you giving back to the community, I strive to do so myself. If only i could find the time between work, eat and sleep :)
This looks like what i need, i have downloaded it and will try integrate it into my code
Thanks Again!
"S. Justin Gengo [MCP]" <justin@[no_spam_please]aboutfortunate. com> wrote in message news:uA******** ******@TK2MSFTN GP10.phx.gbl... Grant,
I have a free javascript component on my website (comes with all source code) that has as one of its methods a disable submit script. The code hasn't been updated for .net 2.0 yet, but it's an easy conversion from 1.1 to 2.0. I just haven't had time to do it yet. If you take that code and add your javascript for displaying your message to it you'll have what you need. Another nice feature of the script is that before it disables the submit button it first calls the microsoft javascripts that handle page validation so that the button won't be disabled if the page isn't valid.
If you have any questions about converting the script or adding your bit of javascript for your load message to it feel free to email me.
You may see a demo of the script (#3) and download the entire component as a .net 1.1 project from here: http://www.aboutfortunate.com?page=javascriptdemo
-- Sincerely,
S. Justin Gengo, MCP Web Developer / Programmer
www.aboutfortunate.com
"Out of chaos comes order." Nietzsche "Grant Merwitz" <gr***@workshar e.com> wrote in message news:en******** ******@TK2MSFTN GP12.phx.gbl... hi
I am using Javascript to do my validation This is so i can display a loading message after a form is submitted.
Now, currently i do so like this.
I have a button, textbox and label like so:
<asp:textbox id="tb" runat="server"/> <asp:Button id="btn" runat="server" text="Submit" /> <asp:Label id="lbl" runat="server" />
I then have a javascript function like so:
function validate() { if(document.get ElementById('tb ').value == '') { document.getEle mentById('lbl') .innerHTML = "please fill in textbox"; return false; } else { document.getEle mentById('lbl') .innerHTML = "Loading... "; return true; } }
And i attach this to the button in the code behind like so:
btn.Attributes. Add("onclick", "JavaScript : return validate();");
now, this works perfectly. but what i would like to do, is disable the button if the value returned is true. Like this: else { document.getEle mentById('lbl') .innerHTML = "Loading... "; document.getEle mentbyId('btn') .enables = false; return true; }
But when i try this, the form will not submit. How can i achieve what i'm trying to do here?
Submit a form only if validated, and disable the button if so?
TIA
Grant
Worked perfectly!!!!
"Grant Merwitz" <gr***@workshar e.com> wrote in message
news:ON******** ******@TK2MSFTN GP10.phx.gbl... Thanks this sounds like what i need.
I've used the form.submit before, but then everything has to be in the page_load method. This sounds like a smarter option!
Thanks!
"slagomite" <sl*******@gmai l.com> wrote in message news:11******** **************@ z14g2000cwz.goo glegroups.com.. . Hrm, interesting. I was able to replicate this -- apparently if the calling object gets disabled, the browser cancels any subsequent actions once control leaves the validate() function.
I was able to work around this by explicitly calling the "__doPostBack() " method in the validate() function -- making an explicit call to this should be identical to the form itself being posted (if you create a LinkButton control and look at the page source, you'll see that ASP.NET just does the same thing -- the LinkButton's "onclick" event makes an explicit call to __doPostBack(), with its ID as the argument).
So try this (note you'll have to create this script from the server-side -- i.e., in the Page.PreRender handler -- in order to get the reference to the postback method):
StringBuilder sb = new StringBuilder() ; sb.Append("<scr ipt language='javas cript'>\r\n"); sb.Append("func tion validate()\r\n" ); sb.Append("{\r\ n"); sb.Append(" if(document.get ElementById('tb ').value == '')\r\n"); sb.Append(" {\r\n"); sb.Append(" document.getEle mentById('lbl') .innerHTML = 'Try again...';\r\n" ); sb.Append(" return false;\r\n"); sb.Append(" }\r\n"); sb.Append(" else\r\n"); sb.Append(" {\r\n"); sb.Append(" document.getEle mentById('lbl') .innerHTML = 'Loading...';\r \n"); sb.Append(" "); sb.Append(this. GetPostBackEven tReference(btn) ; sb.Append(";\r\ n"); sb.Append(" return true;\r\n"); sb.Append(" }\r\n"); sb.Append("}\r\ n"); sb.Append("</script>\r\n"); this.RegisterCl ientScriptBlock ("_PageScripts" , sb.ToString()); btn.Attributes["onclick"] = "return validate();";
HTH, Luke
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: bbxrider |
last post by:
i'm new to javascript but have programmed lots in vb, cobol, basic, etc
jscript seems much more object oriented to me, much more direct manipulation
of properties at least, than vb, don't know about methods yet
i'm having trouble locating property 'trees' so to speak, at least for
html/web and jscript objects
like in this code:
function MM_preloadImages() {
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var...
|
by: bj |
last post by:
I have several pages that I want to allow the same kind of activity,
so my basic question is how best to structure the interaction (and I
have one related subquestion as well).
Scenario: The user clicks a hyperlink and opens a new window in which
there is a bit of explanatory text. This text will be different for
every link. In addition, there is an image on the page which can be
clicked to close the new window.
(This image should...
|
by: Eli |
last post by:
Hi gurus,
My question is about exchanging data on a basic HTML page between a
JavaScript piece of code and a Java client-side <APPLET> residing on
the same webpage.
To demonstrate the idea of data encription at the client side to
students my idea is to build a simple <FORM> on the webpage with 2
text fields and a submit button. The student fills in the text field
on top and click Submit. At this moment, onsubmit() sends the text
field...
|
by: blueapricot416 |
last post by:
This is a very basic question -- but I can't find the answer after
looking for 20 minutes.
If you code something like:
function set_It() {
setTimeout('Request_Complete("apple", -72)',5000)
}
and call it 50 times, will it cause problems because you are not
|
by: John Bailo |
last post by:
http://www.informationweek.com/software/showArticle.jhtml?articleID=196600515
Developers Embrace Java, Drop Visual Basic
"Developers have abandoned Microsoft's Visual Basic in droves during the
last six months, and they're using Java more than any other development
language, according to a recently published survey."
| |
by: craig.burrell |
last post by:
I'm not a Javascript programmer, and I have a basic question about how
scripts may make use of libraries in Javascript. I thank everyone for
humouring me.
Do all of the libraries required by a script have to reside in the
host environment, or may a custom library be bundled with the script
itself?
I ask because I am trying to assess the significance of Alexander
Sotirov's <a href="http://www.determina.com/security.research/
|
by: Bill H |
last post by:
25 years ago every computer came with some form of Basic interpreter
so you could use yoru computer without having to buy more software. Is
Javascript (teamed with HTML) set to become the new Basic, where
anyone with a computer can start writing code without having to
purchase any expensive languages?
Bill H
|
by: MikeB |
last post by:
Hello All, I am new to ajax and wanted to start by trying something simple.
I have a web form with an updatepanel and then inside the update panel I
have a listbox. Then outside of the updatepanel I have a button. In my
buttons click event in the cs / code behind, I have a loop that just inserts
items in the listbox. My question is, once I click the button and the loop
begins, how do I get it to update the listbox? Does this make since?...
|
by: sheldonlg |
last post by:
This is kind of basic, and I googled but didn't find much help.
I have an array of text element fields. They all need to have the same
name. So, let the name be either all with a or build individually as
a, a, a, etc. The brackets need to be there because I will
obtaining the values of them as an array using $_POST{'a'] in php.
What I want to do is in javascript set the value of an individual
element, say a. I have tried many...
|
by: rmurgia |
last post by:
When a variable is created using Javascript, should it then be able to be read immediately using embedded VB code or does the submit command have to be entered or are the variables between javascript, visual basic, and vbscript non-interchangable?
I created the following code:
<script language="javascript">
function question(){
strReply = confirm('Click Yes if you wish to continue.')
alert(strreply)
}
</script>
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |