jQuery是不是在母版页中使用ASP.NET C#和做工精细的工作与不使用母版页 [英] Jquery is not working in Master Page using ASP.NET C# and working fine with without using master page

查看:199
本文介绍了jQuery是不是在母版页中使用ASP.NET C#和做工精细的工作与不使用母版页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这code正常工作在.aspx页面中没有任何问题。但是,如果使用母版页则没有什么作品在这里很好,我试图把JQuery的脚本母版页,即使再没有什么工作。有没有什么事情的设置需要在这里完成。仍然没有得到为什么信息DIV没有加载计数。下面是链接

This code works fine in .aspx page no issues. but if i use master page then nothing works fine here,i tried placing the JQuery script in Master page, even then nothing is working. is there any thing setting need to be done here. Still not getting why info div is not loading count. Below is the link

<script type="text/javascript" src="scripts/jquery-1.3.2-vsdoc2.js"></script>

我是指下列博客也:

I refer following blog also:

的http:// mwtech.blogspot.co.il/2009/04/2-ways-to-load-jquery-from-aspnet.html

MasterPage.master code:

MasterPage.master code:

 <head runat="server">
<title></title>

   <script type="text/javascript" src="scripts/jquery-1.3.2-vsdoc2.js">          </script>



<asp:ContentPlaceHolder id="head" runat="server">
</asp:ContentPlaceHolder>

<form id="form1" runat="server">

 <div>
    <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">

    </asp:ContentPlaceHolder>
</div>

</form>

</body>

</html>

Default2.aspx code

Default2.aspx code


 <script type="text/javascript">

     var Editor1 = '#Editor1';
     var Editor1CountLimit = 50
     var Editor1InfoArea = '#Info';

     var Editor2 = '#Editor2';
     var Editor1InfoArea1 = '#Info1';

     $(document).ready(function () {
         TrackCharacterCount(Editor1, Editor1CountLimit, Editor1InfoArea);
         TrackCharacterCount(Editor2, Editor1CountLimit, Editor1InfoArea1);
     });

     function TrackCharacterCount(ctl, limit, info) {
         var editor = $(ctl).contents().find('iframe').eq(2);
         $(editor).load(function () {
             var txt = $(this).contents().find('body').text();
             $(info).html(txt.length); //set initial value 
             $(this).contents().keyup(function () {
                 var txt = $(this).contents().find('body').text();

                 if (txt.length > limit)
                     $(info).html(txt.length).css("color", "red");
                 else
                     $(info).html(txt.length).css("color", "");
             });
         });
     }

     function ValidateEditor1Length(source, args) {
         var editor = $(Editor1).contents().find('iframe').eq(2);
         var txt = editor.contents().find('body').text();
         var isValid = txt.length > 0 && txt.length <= Editor1CountLimit;
         args.IsValid = isValid;
     }


     function ValidateEditor1Length1(source, args) {
         var editor = $(Editor2).contents().find('iframe').eq(2);
         var txt = editor.contents().find('body').text();
         var isValid = txt.length > 0 && txt.length <= Editor1CountLimit;
         args.IsValid = isValid;
     }

</script> 


      <asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>

            <div id="Info">Info</div>

  <%--  <cc1:Editor ID="Editor1" runat="server" />--%>
    <cc1:Editor ID="Editor1" runat="server" />
    <asp:CustomValidator ID="CustomValidator1" runat="server" ControlToValidate="Editor1" ClientValidationFunction="ValidateEditor1Length" ErrorMessage="Exceeded Character Limit"></asp:CustomValidator>


   <div id="Info1">Info</div>
   <%-- <cc1:Editor ID="Editor2" runat="server" />--%>
    <cc1:Editor ID="Editor2" runat="server" />
    <asp:CustomValidator ID="CustomValidator2" runat="server" ControlToValidate="Editor2" ClientValidationFunction="ValidateEditor1Length1" ErrorMessage="Exceeded Character Limit"></asp:CustomValidator>

</div>
<asp:Button ID="Button1" runat="server" Text="Button" />

感谢您。

推荐答案

我有同样的问题。当浏览器客户端查看输出源$ C ​​$ C我注意到,所有的IDS分别与ContentPlaceHolderID修改为ID本身之前preFIX,所以Id's的jQuery一直在寻找不存在了。

I had same problem. When viewing output source code in browser client I noticed that all "ids" were modified with the ContentPlaceHolderID as a prefix before the id itself, so the Id´s jQuery was looking for did not exist anymore.

解是包括参数的ClientIDMode在子页面中的内容部分=静态,以便标识对象保留在内容网页相同,和jQuery可以由原始的id发现它

Solution was to include the parameter ClientIDMode="Static" in the "Content section" of the child page so id objects remain the same on content pages, and jQuery can find it by the original id.

希望它帮助。

这篇关于jQuery是不是在母版页中使用ASP.NET C#和做工精细的工作与不使用母版页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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