My answer was designed around having the ASP.NET validators run on the page
in the onchange event. You show code that tries to validate some other way.
I'm not sure why. The CompareValidator can validate currency. Set its
Type=Currency and Operator=DataTypeCheck.
I did make a mistake with my previous answer. I thought that
Page.GetPostBackEventReference() created the validation javascript code as
well as __doPostBack. It only creates __doPostBack.
1. Use the CompareValidator
2. TextBox1.Attributes.Add("onchange", "if (typeof(Page_ClientValidate) ==
'function') {Page_ClientValidate(); if (!Page_BlockSubmit)" +
Page.GetPostBackEventReference(TextBox1, "")) + "}"
If you try it with your custom function, do this:
TextBox1.Attributes.Add("onchange", "if
ValidateControlForCurrency('txtTest')){" +
Page.GetPostBackEventReference(TextBox1, "")) + "}"
Be aware that AutoPostBack writes its own onchange code. You will see 2
onchange attributes when its on. The first of them is run by the browser.
That usually is the AutoPostBack code, not yours.
--- Peter Blum
www.PeterBlum.com
Email:
PL****@PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx
"Prodip Saha" <ps***@bear.com> wrote in message
news:ex**************@TK2MSFTNGP10.phx.gbl...
Hi Peter,
Thanks for the reply. I have tried the approach that you have mentioned.
The code looks as if it will submit the form but it does not submit unless I
have the AutoPostBack set to True. The html (in view source) look like the
following --
<td>
<input
name="txtTest"
type="text"
value="0.00"
id="txtTest"
onChange="if(ValidateControlForCurrency('txtTest') ){
__doPostBack('txtTest',''); }"
language="javascript"
style="width:100px;"
/>
</td>
Any creative idea is welcome. Thanks.
Prodip
"Peter Blum" <PL****@Blum.info> wrote in message
news:Oz**************@TK2MSFTNGP11.phx.gbl... When AutoPostBack is enabled, it adds client-side scripts to the control
that call __doPostBack without calling the client-side validation
function. Here's how to fix that:
1. Set AutoPostBack to false. (Yes, turn it off. We will implement it
again.)
2. Add an onchange event that calls the scripts returned by
Page.GetPostBackEventReference().
TextBox1.Attributes.Add("onchange",
Page.GetPostBackEventReference(TextBox1, ""))
--- Peter Blum
www.PeterBlum.com
Email: PL****@PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx
"Prodip Saha" <ps***@bear.com> wrote in message
news:Oj**************@TK2MSFTNGP10.phx.gbl... Dear ASP.NET Gurus,
I have a TextBox control with AutoPostBack set to true to execute the
server scripts. I also, added some client script for validation.What I want
is--execute the client script and if the cleint script returns true
only then I want to execute the server scripts. Am I asking too much or is
it achievable? Please don't give me an answer like --just validate on the
server side...
Some Background:-
I have deligated an event handler to the textChanged event on the TextBox control and I have added the client script as an attribute of the TextBox. I have tried the code different ways but with no luck...
txtTest.Attributes.Add("onChange","IsCurrency('txt Test');");
txtTest.Attributes.Add("onChange","if(IsCurrency(' txtTest')){doSomething()}e lse ");
The first approach will add __doPostBack script automatically at the
end of the client script (after the semi colon) since I have the auto
postback set to true. Problem is --it execute both the client and server scripts.
The second approach will add __doPostback script after the "else"
keyword. This sounds a doable one. The problem is--it does not execute the
server script (i.e. the __doPostback does not get executed to submit the
Form).
Thanks in advance.
Prodip Saha