C# .NET - To display alert messge using javascript in textchange event

Asked By abinav shankar on 01-Feb-12 05:46 AM


I want to check the number of days entered in a text box is not more than 15 days if it exceeds i want to display an alert message to the user how to do it using javascript

kalpana aparnathi replied to abinav shankar on 01-Feb-12 05:58 AM

Try this way:

function checkDate()
    // define date string to test
    var txtDate = document.getElementById('txtDate').value;
    // check date and print message
    if (your conditon for 15 days) {
    else {
      alert('Invalid !');
dipa ahuja replied to abinav shankar on 01-Feb-12 06:01 AM
<asp:UpdatePanel runat="server" ID="up1">
    Enter :
    <asp:TextBox runat="server" ID="txt1" AutoPostBack="true" OnTextChanged="txt1_Changed" />
    <div runat="server" id="UserAvailability">
    <br />
Code Behind:
protected void txt1_Changed(object sender, EventArgs e)
  int numdays = int.Parse(txt1.Text);
  if (numdays > 15)
    Response.Write("<script>alert('enter value in range 1-15')</script>");
Chintan Vaghela replied to abinav shankar on 01-Feb-12 06:22 AM


Onchange event set following code

protected void txtDays_TextChanged(object sender, EventArgs e)


int numdays = 0;

            if (txtDays.Text != "")


              numdays = Convert.ToInt32(txtDays.Text);


            if (numdays > 15)


              string strimsg = "Number is Exceeds 15 Days";// Set Your OWN message here

              string strJavaScript = "<script language = javascript type=text/Javascript> alert('" + strimsg + "')</script>";

              this.Page.RegisterClientScriptBlock("Key4", strJavaScript);



Hope this is helpful !