473,395 Members | 1,938 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How Do I Combine the Cleint & Server Script?

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

Nov 18 '05 #1
4 2439
Try this, change the following
txtTest.Attributes.Add("onChange","IsCurrency('txt Test');")
t
txtTest.Attributes.Add("onChange","return IsCurrency('txtTest');")

Remove your _dopostback call from the IsCurrency function. Keep Autopostback of the textbox as true
Inside the IsCurrency return true if the validation passes or false if it fails

See if that helps
Suresh
----- Prodip Saha wrote: ----

Dear ASP.NET Gurus
I have a TextBox control with AutoPostBack set to true to execute the serve
scripts. I also, added some client script for validation.What I wan
is--execute the client script and if the cleint script returns true onl
then I want to execute the server scripts. Am I asking too much or is i
achievable? Please don't give me an answer like --just validate on th
server side..

Some Background:
I have deligated an event handler to the textChanged event on the TextBo
control and I have added the client script as an attribute of the TextBox.
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()}
lse ")

The first approach will add __doPostBack script automatically at the end o
the client script (after the semi colon) since I have the auto postback se
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 serve
script (i.e. the __doPostback does not get executed to submit the Form)

Thanks in advance
Prodip Sah


Nov 18 '05 #2
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

Nov 18 '05 #3
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


Nov 18 '05 #4
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



Nov 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Luklrc | last post by:
Hi, I'm having to create a querysting with javascript. My problem is that javscript turns the "&" characher into "&amp;" when it gets used as a querystring in the url EG: ...
0
by: Michelle Keys | last post by:
I am trying to call a print function to print a string from a database using javascript. Which is RC_DATA of Varchar2(2500). This is a javascript is not being used. I have a thing that needs to...
11
by: Jeremy | last post by:
How can one stop a browser from converting &amp; to & ? We have a textarea in our system wehre a user can type in some html code and have it saved to the database. When the data is retireved...
2
by: drurjen | last post by:
Good morning. I am importing an XLS file into one of my tables. The fields are: Date Id Time IO 12/22/2006 2 12:48:45 PM 9 12/22/2006 16 5:40:55 AM 1 12/22/2006 16 12:03:59 PM 2 ...
1
by: zwieback89 | last post by:
Hi, I am still not able to get this working in a simple page. Please help me. I am badly stuck.... I am trying to view the contents of the Beverage Category. I have built it like a hierarchy...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
7
by: bhavin30 | last post by:
Is there a way to obtain user information (using LOGON_USER server variables) when you have set up the security to Anonymous Access? I have tried setting the security to both Anonymous + Window...
39
by: dancer | last post by:
Can somebody tell me why I get this message with the following code? Compiler Error Message: BC30452: Operator '&' is not defined for types 'String' and 'System.Web.UI.WebControls.TextBox'. ...
1
by: bluereign | last post by:
Thank you for your assistance. I am a novice looking to JOIN and append or combine records from 2 current Tables into 2 new Tables named below. I have been able to JOIN Tables with the script...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.