Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

Ajax not working during Button Click event.

$
0
0

Hi,

I have a text box and a button. If I click on the button without entering a value in the textbox the required field validator must show the error message. On the OnClick event of the button I have some computations to do. I also store the value of the textbox in the database during the OnClick event of the button. 

So now when I leave the textbox empty and click on the button, instead of the requiredfield error, I get an error for the computation.

ASP Code

<asp:TextBox runat="server" ID="txtHeight"  />

<asp:DropDownList runat="server" ID="cbHeight" CssClass="Choice">
<asp:ListItem Text="cms" Value="cms" Selected="True"></asp:ListItem>
<asp:ListItem Text="inches" Value="inches"></asp:ListItem>
</asp:DropDownList>

<asp:RequiredFieldValidator runat="server" ForeColor="Red" ID="rqHeight" ErrorMessage="Please enter your height"
ControlToValidate="txtHeight"/>

<asp:Button runat="server" ID="btnCompute" Text="COMPUTE" OnClick="btnCompute_Click" />

Code Behind

protected void btnRegister_Click(object sender, EventArgs e)
{

double cmsconvFactor = 2.54;

if (cbHeight.SelectedIndex == 1)
{
height = Convert.ToDouble(txtHeight.Text.Trim()) * cmsconvFactor;
}
else
{
height = Convert.ToDouble(txtHeight.Text.Trim()) / 100;
}

localhost.Service Computation = new localhost.Service();
Computation.Compute(height);
}

When I click on the compute button without entering any value in the textbox, i get an error"Input string was not in correct format" in the line height = Convert.ToDouble(txtHeight.Text.Trim()) / 100;

Why is th requiredfieldvalidator not called here??  Require help urgently

Thanks


Viewing all articles
Browse latest Browse all 5678

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>