ํƒœ๊ทธ ๋ณด๊ด€๋ฌผ: word-count

word-count

WebForms UnobtrusiveValidationMode์—๋Š” โ€˜jqueryโ€™์— ๋Œ€ํ•œ ScriptResourceMapping์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค. jquery (๋Œ€์†Œ ๋ฌธ์ž ๊ตฌ๋ถ„)๋ผ๋Š” ScriptResourceMapping์„ ์ถ”๊ฐ€ํ•˜์‹ญ์‹œ์˜ค objDiv.innerHTML = โ€œ0

Visual Studio 2012๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์›น ์‘์šฉ ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ํ…์ŠคํŠธ ์ƒ์ž์— ๋‹จ์–ด ์ˆ˜๋ฅผ ์ถ”๊ฐ€ํ•˜๋ ค๊ณ ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ์ž๋ฐ” ์Šคํฌ๋ฆฝํŠธ ์ฝ”๋“œ์™€ HTML ์ฝ”๋“œ๋ฅผ ์ถ”๊ฐ€ ํ•œ ํ›„. ์œ„์—์„œ ์„ค๋ช…ํ•œ๋Œ€๋กœ ์˜ค๋ฅ˜๊ฐ€ ๋‚˜ํƒ€๋‚ฉ๋‹ˆ๋‹ค.

์—ฌ๊ธฐ ๋‚ด ์ž๋ฐ” ์Šคํฌ๋ฆฝํŠธ๊ฐ€ ์ฝ”๋”ฉ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.

์ฝ”๋“œ :

function validateLimit(obj, divID, maxchar) {

objDiv = get_object(divID);

if (this.id) obj = this;

var remaningChar = maxchar - trimEnter(obj.value).length;

if (objDiv.id) {
    objDiv.innerHTML = remaningChar + " characters left";
}
if (remaningChar <= 0) {
    obj.value = obj.value.substring(maxchar, 0);
    if (objDiv.id) {
        objDiv.innerHTML = "0 characters left";
    }
    return false;
}
else
{ return true; }
}

function get_object(id) {
var object = null;
if (document.layers) {
    object = document.layers[id];
} else if (document.all) {
    object = document.all[id];
} else if (document.getElementById) {
    object = document.getElementById(id);
}
return object;
}

function trimEnter(dataStr) {
return dataStr.replace(/(\r\n|\r|\n)/g, "");
}

๋งˆ์Šคํ„ฐ ํŽ˜์ด์ง€์˜ ์„œ๋ฒ„ ์ฝ”๋“œ

<script type="text/javascript" src="js/JScript.js" ></script>

ASPX ์ฝ”๋“œ, (HTML ์ฝ”๋“œ)

<tr>
<th style="width: 595px; height: 135px;">Official Report :</th>
<td colspan="4" style="height: 135px">
  <asp:TextBox ID="tbofficial" runat="server" Height="121px" TextMode="MultiLine" Width="878px" MaxLength="500"   ToolTip="Summary:(500 characters)" onkeyup="return validateLimit(this, 'lblMsg1', 500)" ></asp:TextBox>
  <div id="lblMsg1">500 characters left</div>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
        ControlToValidate="tbofficial" Display="Dynamic"
        SetFocusOnError="True">*</asp:RequiredFieldValidator>
  <br />
  <asp:Label ID="lblmsg" runat="server"></asp:Label>
  <br />
  <br />
        <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />
  <asp:Button ID="btnClear" runat="server" Text="Clear" OnClick="btnClear_Click" />
        </td>
</tr>


๋‹ต๋ณ€

4.5 ์ด์ „ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ ๋ชจ๋“œ๋ฅผ ํ™œ์„ฑํ™”ํ•˜๋ ค๋ฉด web.config ํ‚ค๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

ValidationSettings : UnobtrusiveValidationMode ์— ๋Œ€ํ•œ ์ถ”๊ฐ€ ์ •๋ณด :

ASP.NET์—์„œ ๋‚ด์žฅ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ๊ธฐ ์ปจํŠธ๋กค์ด ํด๋ผ์ด์–ธํŠธ ์ชฝ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ ๋…ผ๋ฆฌ์— ๋ˆˆ์— ๋„์ง€ ์•Š๋Š” JavaScript๋ฅผ ์‚ฌ์šฉํ•˜๋„๋ก ์ „์—ญ ์ ์œผ๋กœ ์„ค์ •ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค.

์œ ํ˜• : ๋ˆˆ์— ๋„์ง€ ์•Š๋Š” ๊ฒ€์ฆ ๋ชจ๋“œ

๊ธฐ๋ณธ๊ฐ’ : ์—†์Œ

์„ค๋ช… :์ด ํ‚ค ๊ฐ’์„ โ€œ์—†์Œโ€ [๊ธฐ๋ณธ๊ฐ’]์œผ๋กœ ์„ค์ •ํ•˜๋ฉด ASP.NET ์‘์šฉ ํ”„๋กœ๊ทธ๋žจ์€ ํด๋ผ์ด์–ธํŠธ ์ชฝ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ ๋…ผ๋ฆฌ์— 4.5 ์ด์ „ ๋™์ž‘ (ํŽ˜์ด์ง€์˜ JavaScript ์ธ๋ผ์ธ)์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ์ด ํ‚ค ๊ฐ’์„ โ€œWebFormsโ€๋กœ ์„ค์ •ํ•˜๋ฉด ASP.NET์€ ํด๋ผ์ด์–ธํŠธ ์ธก ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ ๋…ผ๋ฆฌ๋ฅผ ์œ„ํ•ด ์ถ”๊ฐ€ ๋œ ์Šคํฌ๋ฆฝํŠธ ์ฐธ์กฐ์˜ HTML5 ๋ฐ์ดํ„ฐ ํŠน์„ฑ ๋ฐ ๋Šฆ๊ฒŒ ๋ฐ”์ธ๋”ฉ ๋œ JavaScript๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค .

์˜ˆ:

    <appSettings>
      <add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
    </appSettings>

๋‹ต๋ณ€

์ƒˆ๋กœ์šด ๊ธฐ๋Šฅ์„ ๋น„ํ™œ์„ฑํ™”ํ•˜๋Š” ๋Œ€์‹  ์˜ค๋ฅ˜ ์ง€์นจ์„ ๋”ฐ๋ฅด๋„๋ก ์„ ํƒํ–ˆ์Šต๋‹ˆ๋‹ค. ๋‚ด global.asax.cs์— ๋‹ค์Œ์„ ์ถ”๊ฐ€ํ–ˆ์Šต๋‹ˆ๋‹ค.

protected void Application_Start(object sender, EventArgs e)
{
    string JQueryVer = "1.7.1";
    ScriptManager.ScriptResourceMapping.AddDefinition("jquery", new ScriptResourceDefinition
    {
        Path = "~/Scripts/jquery-" + JQueryVer + ".min.js",
        DebugPath = "~/Scripts/jquery-" + JQueryVer + ".js",
        CdnPath = "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-" + JQueryVer + ".min.js",
        CdnDebugPath = "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-" + JQueryVer + ".js",
        CdnSupportsSecureConnection = true,
        LoadSuccessExpression = "window.jQuery"
    });
}

์ด๊ฒƒ์€ ์Šคํฌ๋ฆฝํŠธ ๋ฆฌ์†Œ์Šค ๋งคํ•‘์˜ ์žฅ์  ์ค‘ ์ผ๋ถ€๋ฅผ ๊ฐ•์กฐ ํ•˜๋Š” msdn ๋ธ”๋กœ๊ทธ ๊ฒŒ์‹œ๋ฌผ ์—์„œ ๋น„๋กฏ๋œ ๊ฒƒ์ž…๋‹ˆ๋‹ค. โ€œdebug = trueโ€, EnableCDN ๋“ฑ์„ ๊ธฐ๋ฐ˜์œผ๋กœ ์Šคํฌ๋ฆฝํŠธ ํŒŒ์ผ์˜ ์ „๋‹ฌ์„ ์ค‘์•™ ์ง‘์ค‘์‹์œผ๋กœ ์ œ์–ดํ•˜๋Š” โ€‹โ€‹๊ฒƒ์ด ํŠนํžˆ ์ค‘์š”ํ–ˆ์Šต๋‹ˆ๋‹ค.


๋‹ต๋ณ€

ํด๋ผ์ด์–ธํŠธ ์ธก ์œ ํšจ์„ฑ ๊ฒ€์ฆ์„ ์œ„ํ•ด ๋ฐฉํ•ด๋ฐ›์ง€ ์•Š๋Š” JavaScript๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋„๋ก ์„ค์ •ํ•˜๋Š” ๋ฐฉ๋ฒ•์—๋Š” ์ตœ์†Œํ•œ ์„ธ ๊ฐ€์ง€๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.

  1. web.config ํŒŒ์ผ์— ๋‹ค์Œ์„ ์ถ”๊ฐ€ํ•˜์‹ญ์‹œ์˜ค.
    <configuration>
      <appSettings>
        <add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
      </appSettings>
    </configuration>
  2. System.Web.UI.ValidationSettings.UnobtrusiveValidationMode์ •์  ์†์„ฑ ๊ฐ’ ์„System.Web.UI.UnobtrusiveValidationMode.None
  3. System.Web.UI.Page.UnobtrusiveValidationMode์ธ์Šคํ„ด์Šค ์†์„ฑ ๊ฐ’ ์„System.Web.UI.UnobtrusiveValidationMode.None

ํŽ˜์ด์ง€๋ณ„๋กœ ๊ธฐ๋Šฅ์„ ๋น„ํ™œ์„ฑํ™”ํ•˜๋ ค๋ฉด Page.UnobtrusiveValidationModepage ์ง€์‹œ๋ฌธ์„ ์‚ฌ์šฉํ•˜์—ฌ ์†์„ฑ ์„ ์„ค์ •ํ•˜๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค.

<%@ Page Language="C#" UnobtrusiveValidationMode="None" %>

๋‹ต๋ณ€

์ƒˆ๋กœ์šด ๋ฒ„์ „์˜ ASP.NET์—์„œ๋Š” ๋ˆˆ์— ๋„์ง€ ์•Š๋Š” ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ๊ฐ€ ๊ธฐ๋ณธ์ ์œผ๋กœ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค. ๋ˆˆ์— ๋„์ง€ ์•Š๋Š” ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ๋Š” ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ๋ฅผ ์œ„ํ•ด ์ธ๋ผ์ธ JavaScript๋ฅผ jQuery๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์ž‘์€ JavaScript ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋กœ ๋Œ€์ฒดํ•˜์—ฌ ํŽ˜์ด์ง€ ํฌ๊ธฐ๋ฅผ ์ค„์ด๋Š” ๊ฒƒ์„ ๋ชฉํ‘œ๋กœํ•ฉ๋‹ˆ๋‹ค.

๋‹ค์Œ์„ ํฌํ•จํ•˜๋„๋ก web.config๋ฅผ ํŽธ์ง‘ํ•˜์—ฌ ๋น„ํ™œ์„ฑํ™” ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

<appSettings>
  <add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
</appSettings>

๋˜๋Š” global.asax์—์„œ Application_Start ๋ฉ”์†Œ๋“œ๋ฅผ ์ˆ˜์ •ํ•˜์—ฌ ์˜ฌ๋ฐ”๋ฅด๊ฒŒ ๊ตฌ์„ฑํ•˜์‹ญ์‹œ์˜ค.

void Application_Start(object sender, EventArgs e)
{
    RouteConfig.RegisterRoutes(System.Web.Routing.RouteTable.Routes);
    ScriptManager.ScriptResourceMapping.AddDefinition("jquery",
        new ScriptResourceDefinition
        {
            Path = "/~Scripts/jquery-2.1.1.min.js"
        }
    );
}

C # ๋ฐ VB์˜ ASP.NET 4.5.1 ์‹œ์ž‘ ํŽ˜์ด์ง€ 397์—์„œ๋Š” ๋ˆˆ์— ๊ฑฐ์Šฌ๋ฆฌ์ง€ ์•Š๋Š” ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ์˜ ์ด์ ๊ณผ์ด๋ฅผ ๊ตฌ์„ฑํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์„ค๋ช…ํ•ฉ๋‹ˆ๋‹ค.

RouteConfig๋ฅผ ์ฐพ๋Š” ์‚ฌ๋žŒ๋“ค์„ ์œ„ํ•ด. Visual Studio์—์„œ App_Code ํด๋”์— ์ƒˆ ํ”„๋กœ์ ํŠธ๋ฅผ ๋งŒ๋“ค๋ฉด ์ž๋™์œผ๋กœ ์ถ”๊ฐ€๋ฉ๋‹ˆ๋‹ค. ๋‚ด์šฉ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Routing;
using Microsoft.AspNet.FriendlyUrls;

namespace @default
{
    public static class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            var settings = new FriendlyUrlSettings();
            settings.AutoRedirectMode = RedirectMode.Permanent;
            routes.EnableFriendlyUrls(settings);
        }
    }
}

๋‹ต๋ณ€

global.asax์˜ b_levitt โ€ฆ์˜ ๋‹ต๋ณ€์— ์กฐ๊ธˆ ๋” ์ถ”๊ฐ€ํ•˜๋ ค๋ฉด :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using System.Web.UI;

namespace LoginPage
{
    public class Global : System.Web.HttpApplication
    {
        protected void Application_Start(object sender, EventArgs e)
        {
            string JQueryVer = "1.11.3";
            ScriptManager.ScriptResourceMapping.AddDefinition("jquery", new ScriptResourceDefinition
            {
                Path = "~/js/jquery-" + JQueryVer + ".min.js",
                DebugPath = "~/js/jquery-" + JQueryVer + ".js",
                CdnPath = "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-" + JQueryVer + ".min.js",
                CdnDebugPath = "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-" + JQueryVer + ".js",
                CdnSupportsSecureConnection = true,
                LoadSuccessExpression = "window.jQuery"
            });
        }
    }
}

default.aspx์—์„œ

<body>
   <form id="UserSectionForm" runat="server">
     <asp:ScriptManager ID="ScriptManager" runat="server">
          <Scripts>
               <asp:ScriptReference Name="jquery" />
          </Scripts>
     </asp:ScriptManager>
     <%--rest of your markup goes here--%>
   </form>
</body>

๋‹ต๋ณ€

๋‚˜๋Š” ๊ฐ™์€ quandary๋ฅผ ๋งŒ๋‚ฌ๋‹ค๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค. ๋‹ค์Œ์œผ๋กœ ๋ณ€๊ฒฝํ–ˆ์„ ๋•Œ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•˜๊ธฐ ์‹œ์ž‘ํ–ˆ์Šต๋‹ˆ๋‹ค.

</system.web>
<httpRuntime targetFramework="4.5"/>

์œ„์—์„œ ์„ค๋ช…ํ•œ ์˜ค๋ฅ˜ ๋ฉ”์‹œ์ง€๊ฐ€ ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค.

์ฒจ๊ฐ€:

<appSettings>
  <add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />

๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐ ํ•˜์ง€๋งŒ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ ์ปจํŠธ๋กค / ์Šคํฌ๋ฆฝํŠธ์—์„œ Javascript ๋Ÿฐํƒ€์ž„ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค.
๋‹ค์Œ์œผ๋กœ ๋ณ€๊ฒฝํ•˜๋ฉด

</system.web>
<httpRuntime targetFramework="4.0"/>

๊ดœ์ฐฎ์•„ ์•ผ ํ•˜์ง€๋งŒ ๋‚˜๋จธ์ง€ ์ฝ”๋“œ๊ฐ€ ์›ํ•˜๋Š”๋Œ€๋กœ ์ž‘๋™ํ•˜๋Š”์ง€ ํ™•์ธํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค. 4.5 ์ด์ƒ์—์„œ๋งŒ ์‚ฌ์šฉํ•  ์ˆ˜์žˆ๋Š” ์ผ๋ถ€ ์ƒˆ๋กœ์šด ๊ธฐ๋Šฅ์„ ํฌ๊ธฐํ•ด์•ผ ํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.

PS์ด ์†”๋ฃจ์…˜์„ ๊ตฌํ˜„ํ•˜๊ธฐ ์ „์— ๋‹ค์Œ์„ ์ฝ์–ด ๋ณด๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค. ํŠนํžˆ ๋น„๋™๊ธฐ ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ :

https://blogs.msdn.microsoft.com/webdev/2012/11/19/all-about-httpruntime-targetframework/

2017 ๋…„ 4 ์›” ์—…๋ฐ์ดํŠธ :
๋ช‡ ๊ฐ€์ง€ ์‹คํ—˜๊ณผ ํ…Œ์ŠคํŠธ๋ฅผ ๊ฑฐ์นœ ํ›„ ์ž‘๋™ํ•˜๋Š” ์กฐํ•ฉ์„ ์ƒ๊ฐํ•ด ๋ƒˆ์Šต๋‹ˆ๋‹ค.

<add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
<httpRuntime targetFramework="4.5.1" />

์™€:

jQuery ๋ฒ„์ „ 1.11.3


๋‹ต๋ณ€

์ œ์–ด ์œ ํšจ์„ฑ ๊ฒ€์ฆ๊ธฐ๋กœ ์ธํ•ด ๋ฌธ์ œ์ ์ด ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค. ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์›น ํŽ˜์ด์ง€์— J Query ์ฐธ์กฐ๋ฅผ ์ถ”๊ฐ€ ํ•œ ๋‹ค์Œ web.config ํŒŒ์ผ์— ์œ ํšจ์„ฑ ๊ฒ€์ฆ ์„ค์ •์„ ์ถ”๊ฐ€ํ•˜์—ฌ ๋ฌธ์ œ์ ์„ ๊ทน๋ณตํ•˜์‹ญ์‹œ์˜ค. ๋‚˜๋„ ๊ฐ™์€ ๋ฌธ์ œ์— ์ง๋ฉดํ–ˆ๊ณ  ์•„๋ž˜๋Š” ๋‚ด ๋ฌธ์ œ์— ๋Œ€ํ•œ ํ•ด๊ฒฐ์ฑ…์„ ์ฃผ์—ˆ๋‹ค.

1 ๋‹จ๊ณ„:

2 ๋‹จ๊ณ„ :

๋ฌธ์ œ๊ฐ€ ํ•ด๊ฒฐ๋ฉ๋‹ˆ๋‹ค.