本文介绍了Ajax HTML编辑器不使用ASP.NET C#计算母版页中的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不使用母版页,它可以正常运行;当我使用母版页时,它不能运行.

Without using master page it is working perfectly and When I am using master page it is not working.

我认为此TrackCharacterCount函数不在母版页中进行计数.

I think this TrackCharacterCount function is not counting in mastere page.

我也尝试了新的Jquery脚本:

I tried new Jquery script also:

 <script type="text/javascript" src="scripts/jquery-2.1.4.min.js"></script>

母版页设计代码:

  <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>
 </head>
     <body>
    <form id="form1" runat="server">
      <div>
       <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">

      </asp:ContentPlaceHolder>
</div>
  </form>
</body>

Default2.aspx代码:

Default2.aspx Code:

  <%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

  <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit.HTMLEditor" TagPrefix="cc1" %>


   <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">

   </asp:Content>
   <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">


 <script type="text/javascript">

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


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

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


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

推荐答案

将您的脚本放入母版页眉中,就像这样

put your script in masterpage's header somethink like this

<head>
<script type="text/javascript" 
        src="<%# ResolveUrl("~/YourScriptFolder/YourJavascript.js") %>">
</script>
</head>

这篇关于Ajax HTML编辑器不使用ASP.NET C#计算母版页中的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 13:08