Call client side and server side events together.


I have one textbox on my aspx page.

I want to validate amount in that textbox. If it exceeds 100 then the alert message should show that amount is bigger.
And it should not go further. But if the amount is less than or equal to 100, then after checking the condition on
clientside, it should to the server side TextChanged event.

I have written a javascript function which is being called on "onchange" event of textbox and if the value is valid, then
it should call serverside textchanged event of the same textbox.

Please its urgent.



Mark it as Answer if you find it Helpful.

Shailen
0
Shailen
7/5/2008 9:38:43 AM
📁 asp.net.client-side
📃 24353 articles.
⭐ 2 followers.

💬 2 Replies
👁️‍🗨️ 1441 Views

 It you are trying to validate it on server side too, then use compare validator.

 It can validate that text box on first on client and then on server. 

 

==========================================================

 

<asp:CompareValidator ID="CompareValidator1" runat="server" ControlToCompare="TextBox1"
        Display="Dynamic" ErrorMessage="CompareValidator" Operator="LessThanEqual" SetFocusOnError="True"
        ValueToCompare="100"></asp:CompareValidator></div>


Hope it helps.

-Manas

=======================================
If this post is useful to you, please mark it as answer.
0
yeotumitsu
7/5/2008 12:36:14 PM

Or try this:

<script type="text/javascript">
<!--
function validateTextBox(elementRef)
{
 var textBoxValue = parseInt(elementRef.value);

 if ( (isNaN(textBoxValue) == true) || (textBoxValue > 100) )
 {
  alert('Too large!');
  elementRef.focus();
  elementRef.select();
 }
 else
 {
  __doPostBack(elementRef.id, '');
 }
// -->
</script>

And in the CodeBehind file:

private void Page_Load(object sender, System.EventArgs e)
{
 // Insure that the __doPostBack() JavaScript method is created...
 this.GetPostBackEventReference(this, string.Empty);

 TextBox1.Attributes.Add("onchange", "validateTextBox(this);");
}

NC...

0
NC01
7/6/2008 12:08:18 PM
Reply: