JavaScript代码在Ajax模型PopUp中不起作用 [英] JavaScript Code Is Not Working In Ajax Model PopUp

查看:114
本文介绍了JavaScript代码在Ajax模型PopUp中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,

hello friends,

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;
        }
    }







<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>




<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>

推荐答案

以下内容与直接javaScript页面相关,ASP.NET可能会给你一些额外的选项,但是:



虽然有一些方法在它周围,当用AJAX放在那里时,不会在页面上执行javaScript。它们存在,如果您,例如稍后从页面执行的函数,但它们不会自动运行。



有几种方法:你可以改变你的策略并让执行重新加载页面。



如果可行的话,你可以在javaScript中执行弹出消息,用于将AJAX调用作为返回的一部分从(在我的情况下,PHP)。 页面上已有一个弹出窗口将运行,您可以更改它将在AJAX返回时使用的数据。



类似于:



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()





以上只是ajax调用的一部分,就像直接html / javascript / php一样 - 但它如果它适用,应该指明你需要的方式。



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.


这篇关于JavaScript代码在Ajax模型PopUp中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆