Click here to Skip to main content
15,894,343 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hello friends,
C#
in my webpage in a model PopUp Window i am comparing ages present in two textBox,using javascript but somehow it is not working. kindly help to overcome from this issue. Thanks In Advance. my javascript code is:
<pre lang="Javascript">
function CompareAge() {
        var maxage = document.getElementById('<%=txtMaxAge.ClientID%>');
        var minage = document.getElementById('<%=txtMinAge.ClientID%>');
        var val = 'false';
        if (maxage>=minage) {               
            val = 'true';
            return true;
        }
        if (val == 'false') {
            alert('Max-Age Alaways greater than or Equal Min-Age');
            return false;
        }
    }


ASP.NET
<td>
<asp:TextBox ID="txtMaxAge" runat="server" CssClass="TextBox mytextboxinPopUp"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="txtMinAge" runat="server" CssClass="TextBox mytextboxinPopUp"></asp:TextBox>
</td>

ASP.NET
<ul>
                                                            <li>
                                                                <asp:Button ID="btnCancelInPopUpReservation" runat="server" CssClass="button" Text="Cancel" />
                                                            </li>
                                                            <li>
                                                                <asp:Button ID="btnSaveInPopUpReservation" runat="server" CssClass="button" Text="Save" OnClick="btnSaveInPopUpReservation_Click" ValidationGroup="g" OnClientClick="if(!CompareAge()) return false;"/>
                                                            </li>
                                                        </ul>
Posted

1 solution

The following are relevant in straight javaScript pages and ASP.NET may give you some additional options, but:

Although there are some ways around it, javaScript's are not executed on the page when put there by a AJAX. They are present if you, for example a function executed later from the page, but they are not run automatically.

There are a few ways around this: you can change your strategy and have the execution reload the page.

If practical, you can have you popup message executed in the javaScript used to make the AJAX call as part of the return from (in my case, php). A popup already on the page will run and you can change the data it will use at the AJAX return.

Something like:

xmlhttp.onreadystatechange=function() {
  if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200) {
       var ajaxRtn = xmlhttp.responseText; 
       window.alert(ajaxRtn); // This is already part of page, it will execute
  } // if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200)
} // xmlhttp.onreadystatechange=function()


the above is just part of the ajax call as done in straight html/javascript/php - but it should point you in the way you need to go if it's applicable.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900