繁体   English   中英

javascript:如何将安全字符串传递给数组以进行客户端显示而不会搞砸/ ASP.NET C#

[英]javascript: how do I pass safe strings to an array for client side display without messing it up / ASP.NET C#

平台:ASP.NET 3.5 / C#

我的要求是:

我想在服务器端(在C#中)创建一个相当大的数组,并通过它传递给浏览器

Page.ClientScript.RegisterArrayDeclaration("gBank", js);

我的数组是一个二维数组,我正在构建它以将它传递给客户端。 简单案件工作正常。

我的问题是数组的内容 - 有几个字符串,例如

[[4, 'hello there', 'this is \n one'],[5,'again','there's another string']] etc. 

这些字符串可以有新的行,', - 和其他这样的字符,包括<>等。我用'\\ n'替换了'\\ n',这很好,但其他字符如'弄乱了客户端中的数组字符串侧。

如何“安全地”传递这些字符串,以便在客户端没有混淆数组,并且内容按原样显示?


我在Rick Stahl的博客上找到了这段代码

http://www.west-wind.com/weblog/posts/114530.aspx

它似乎工作得很好。

在构建JSON时,您需要正确地转义Javascript字符串文字。

您可以使用WPL并调用Encoder.JavaScriptEncode

但是,最好使用适当的JSON编码器,例如JavaScriptSerializer

我怎么放一个<div>在使用 C# 的 ASP.NET 的侧面导航栏旁边?</div><div id="text_translate"><p> 我想在导航栏<a href="https://i.stack.imgur.com/sBzTI.png" rel="nofollow noreferrer">计划</a>旁边的红色框中插入内容,基本上就像典型的侧导航栏网站一样。</p><p> 但我得到的结果是,<a href="https://i.stack.imgur.com/Cjun4.png" rel="nofollow noreferrer">实际上</a>,我想将它放在导航栏旁边的内容竟然在整个导航栏下方。</p><p> 我使用 Visual Studio 2019、ASP.NET 框架和 C# 语言。 我检查了我的代码并意识到侧导航栏有一个右边距,但我已经相应地调整了它,但它仍然没有工作。</p><p> 下面显示的代码位于home.master下,而<a href="https://i.stack.imgur.com/PooVJ.png" rel="nofollow noreferrer">home.aspx</a>是我的内容中的内容,应该出现在侧面导航栏旁边。 </p><p></p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"><div class="snippet-code"><pre class="snippet-code-css lang-css prettyprint-override"> /*DO NOT EDIT--------------------------------------*/ * { margin: 0px; height:100%; font-family: "Helvetica Neue", "Lucida Grande", "Segoe UI", Arial, Helvetica, Verdana, sans-serif; }.sidebar { width: 190px; margin-right:0; padding-right:0; background-color: #2a2f3b; height: 100%; color: #bbc0c7; display: flex; align-items: center; flex-direction: column; }.sidebar-top, .sidebar-center, .sidebar-bottom { width: 80%; padding: 10px 0; height: auto; display: flex; align-items: center; margin-bottom: 4px; margin-top: 3px; border-bottom: 1px solid #4b4b4b; }.sidebar-bottom{ border: none; margin:0; justify-content: center; } #logo { margin-right: 10px; cursor: pointer; padding-left: 9px; }.brand { font-weight: bold; cursor: pointer; height:auto; }.list { list-style: none; padding: 0px; width: 100%; display: flex; flex-direction: column; }.list-items { margin-bottom: 6px; font-size: 12px; font-weight: 500; cursor: pointer; padding: 10px; border-radius: 10px; }.list-item-text a { color: #bbc0c7; text-decoration: none; }.list-item-icon { width: 30px; font-size: 20px; }.list-items:hover, .list-items.active { background-color: #374151; color: white; } @media only screen and (max-width: 768px) {.sidebar { width: 50px; margin-right: 0; }.brand, .list-item-text, .name-job, #logout { display: none; } } @media only screen and (max-height: 550px) {.sidebar { width: 50px; height: auto; margin-right: 0; }.brand, .list-item-text, .name-job, #logout { display: none; } }.sidebar-bottom { bottom:0; left:0; }.profile { position: relative; padding: 0; width: 100%; }.profile-details { display: flex; align-items: center; } #avatar { height: 38px; width: 38px; object-fit: cover; border-radius: 12px; }.name-job { margin-left: 10px; height: auto; }.name { font-size: 14px; font-weight: 400; }.job { font-size: 12px; } #logout { position: absolute; left: 88%; bottom: 10px; font-size: 20px; border-radius: 12px; height: 20px; cursor: pointer; } /*DO NOT EDIT ^^^^^^^^^^--------------------------------------*/</pre><pre class="snippet-code-html lang-html prettyprint-override"> &lt;body&gt; &lt;asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server"&gt; &lt;/asp:ContentPlaceHolder&gt; &lt;div class="all-content"&gt; &lt;div class="sidebar"&gt; &lt;div class="sidebar-top"&gt; &lt;asp:Image ImageUrl="~/Images/logoicon.png" ID="logo" Height="25px" runat="server" /&gt; &lt;span class="brand"&gt;CoursUs&lt;/span&gt; &lt;/div&gt; &lt;div class="sidebar-center"&gt; &lt;ul class="list"&gt; &lt;li class="list-items active"&gt; &lt;i class="list-item-icon fab fa-safari"&gt;&lt;/i&gt; &lt;span class="list-item-text"&gt;&lt;a href="#"&gt;BrowseCourse&lt;/a&gt;&lt;/span&gt; &lt;/li&gt; &lt;li class="list-items"&gt; &lt;i class="list-item-icon fas fa-search"&gt;&lt;/i&gt; &lt;span class="list-item-text"&gt;&lt;a href="#"&gt;Course Finder&lt;/a&gt;&lt;/span&gt; &lt;/li&gt; &lt;li class="list-items"&gt; &lt;i class="list-item-icon far fa-comments"&gt;&lt;/i&gt; &lt;span class="list-item-text"&gt;&lt;a href="#"&gt;Forum&lt;/a&gt;&lt;/span&gt; &lt;/li&gt; &lt;li class="list-items"&gt; &lt;i class="list-item-icon far fa-question-circle"&gt;&lt;/i&gt; &lt;span class="list-item-text"&gt;&lt;a href="#"&gt;FAQ&lt;/a&gt;&lt;/span&gt; &lt;/li&gt; &lt;li class="list-items"&gt; &lt;i class="list-item-icon far fa-user"&gt;&lt;/i&gt; &lt;span class="list-item-text"&gt;&lt;a href="#"&gt;My Profile&lt;/a&gt;&lt;/span&gt; &lt;/li&gt; &lt;li class="list-items"&gt; &lt;i class="list-item-icon far fa-gem"&gt;&lt;/i&gt; &lt;span class="list-item-text"&gt;&lt;a href="points.aspx"&gt;My Points&lt;/a&gt;&lt;/span&gt; &lt;/li&gt; &lt;li class="list-items"&gt; &lt;i class="list-item-icon far fa-calendar"&gt;&lt;/i&gt; &lt;span class="list-item-text"&gt;&lt;a href="#"&gt;My Appointments&lt;/a&gt;&lt;/span&gt; &lt;/li&gt; &lt;li class="list-items"&gt; &lt;i class="list-item-icon far fa-folder"&gt;&lt;/i&gt; &lt;span class="list-item-text"&gt;&lt;a href="#"&gt;My Drive&lt;/a&gt;&lt;/span&gt; &lt;/li&gt; &lt;li class="list-items"&gt; &lt;i class="list-item-icon fas fa-graduation-cap"&gt;&lt;/i&gt; &lt;span class="list-item-text"&gt;&lt;a href="#"&gt;My Progress&lt;/a&gt;&lt;/span&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;div class="sidebar-bottom"&gt; &lt;div class="profile"&gt; &lt;div class="profile-details"&gt; &lt;asp:Image ImageUrl="~/Images/avatar.png" ID="avatar" runat="server" /&gt; &lt;div class="name-job"&gt; &lt;div class="name"&gt;USER&lt;/div&gt; &lt;div class="job"&gt;Studet&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;i class="list-item-icon fas fa-sign-out-alt" height="34px" id="logout"&gt;&lt;/i&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="container-fluid"&gt; &lt;asp:ContentPlaceHolder ID="ContentPlaceHolder2" runat="server"&gt; &lt;div&gt;&lt;/div&gt; &lt;/asp:ContentPlaceHolder&gt; &lt;/div&gt; &lt;/body&gt;</pre></div></div><p></p></div>

[英]How do I put a <div> beside a side navbar in ASP.NET using C#?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在不使用C#的库的情况下修改PDF并将其流回ASP.NET中的客户端? 如何在没有客户端事件的情况下从ASP.NET代码后面调用jQuery UI对话框? 在ASP.net C#中,如何将参数从Javascript函数传递给onclick处理程序 将 C# ASP.NET 数组传递给 Javascript 数组 将数组传递给Javascript数组C#ASP.NET 如何在客户端C#(asp.net)中检查Caps Lock状态 C# Asp.net MVC - 如何正确传递从外部 API 提取的数据以显示在视图上? ASP.NET C# 中继器 - 如何在没有 Javascript 的情况下将信息传递回服务器? 图像调用ASP实用程序。 如何在没有ASP.NET(C#)的图像的情况下执行此操作 我怎么放一个<div>在使用 C# 的 ASP.NET 的侧面导航栏旁边?</div><div id="text_translate"><p> 我想在导航栏<a href="https://i.stack.imgur.com/sBzTI.png" rel="nofollow noreferrer">计划</a>旁边的红色框中插入内容,基本上就像典型的侧导航栏网站一样。</p><p> 但我得到的结果是,<a href="https://i.stack.imgur.com/Cjun4.png" rel="nofollow noreferrer">实际上</a>,我想将它放在导航栏旁边的内容竟然在整个导航栏下方。</p><p> 我使用 Visual Studio 2019、ASP.NET 框架和 C# 语言。 我检查了我的代码并意识到侧导航栏有一个右边距,但我已经相应地调整了它,但它仍然没有工作。</p><p> 下面显示的代码位于home.master下,而<a href="https://i.stack.imgur.com/PooVJ.png" rel="nofollow noreferrer">home.aspx</a>是我的内容中的内容,应该出现在侧面导航栏旁边。 </p><p></p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"><div class="snippet-code"><pre class="snippet-code-css lang-css prettyprint-override"> /*DO NOT EDIT--------------------------------------*/ * { margin: 0px; height:100%; font-family: "Helvetica Neue", "Lucida Grande", "Segoe UI", Arial, Helvetica, Verdana, sans-serif; }.sidebar { width: 190px; margin-right:0; padding-right:0; background-color: #2a2f3b; height: 100%; color: #bbc0c7; display: flex; align-items: center; flex-direction: column; }.sidebar-top, .sidebar-center, .sidebar-bottom { width: 80%; padding: 10px 0; height: auto; display: flex; align-items: center; margin-bottom: 4px; margin-top: 3px; border-bottom: 1px solid #4b4b4b; }.sidebar-bottom{ border: none; margin:0; justify-content: center; } #logo { margin-right: 10px; cursor: pointer; padding-left: 9px; }.brand { font-weight: bold; cursor: pointer; height:auto; }.list { list-style: none; padding: 0px; width: 100%; display: flex; flex-direction: column; }.list-items { margin-bottom: 6px; font-size: 12px; font-weight: 500; cursor: pointer; padding: 10px; border-radius: 10px; }.list-item-text a { color: #bbc0c7; text-decoration: none; }.list-item-icon { width: 30px; font-size: 20px; }.list-items:hover, .list-items.active { background-color: #374151; color: white; } @media only screen and (max-width: 768px) {.sidebar { width: 50px; margin-right: 0; }.brand, .list-item-text, .name-job, #logout { display: none; } } @media only screen and (max-height: 550px) {.sidebar { width: 50px; height: auto; margin-right: 0; }.brand, .list-item-text, .name-job, #logout { display: none; } }.sidebar-bottom { bottom:0; left:0; }.profile { position: relative; padding: 0; width: 100%; }.profile-details { display: flex; align-items: center; } #avatar { height: 38px; width: 38px; object-fit: cover; border-radius: 12px; }.name-job { margin-left: 10px; height: auto; }.name { font-size: 14px; font-weight: 400; }.job { font-size: 12px; } #logout { position: absolute; left: 88%; bottom: 10px; font-size: 20px; border-radius: 12px; height: 20px; cursor: pointer; } /*DO NOT EDIT ^^^^^^^^^^--------------------------------------*/</pre><pre class="snippet-code-html lang-html prettyprint-override"> &lt;body&gt; &lt;asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server"&gt; &lt;/asp:ContentPlaceHolder&gt; &lt;div class="all-content"&gt; &lt;div class="sidebar"&gt; &lt;div class="sidebar-top"&gt; &lt;asp:Image ImageUrl="~/Images/logoicon.png" ID="logo" Height="25px" runat="server" /&gt; &lt;span class="brand"&gt;CoursUs&lt;/span&gt; &lt;/div&gt; &lt;div class="sidebar-center"&gt; &lt;ul class="list"&gt; &lt;li class="list-items active"&gt; &lt;i class="list-item-icon fab fa-safari"&gt;&lt;/i&gt; &lt;span class="list-item-text"&gt;&lt;a href="#"&gt;BrowseCourse&lt;/a&gt;&lt;/span&gt; &lt;/li&gt; &lt;li class="list-items"&gt; &lt;i class="list-item-icon fas fa-search"&gt;&lt;/i&gt; &lt;span class="list-item-text"&gt;&lt;a href="#"&gt;Course Finder&lt;/a&gt;&lt;/span&gt; &lt;/li&gt; &lt;li class="list-items"&gt; &lt;i class="list-item-icon far fa-comments"&gt;&lt;/i&gt; &lt;span class="list-item-text"&gt;&lt;a href="#"&gt;Forum&lt;/a&gt;&lt;/span&gt; &lt;/li&gt; &lt;li class="list-items"&gt; &lt;i class="list-item-icon far fa-question-circle"&gt;&lt;/i&gt; &lt;span class="list-item-text"&gt;&lt;a href="#"&gt;FAQ&lt;/a&gt;&lt;/span&gt; &lt;/li&gt; &lt;li class="list-items"&gt; &lt;i class="list-item-icon far fa-user"&gt;&lt;/i&gt; &lt;span class="list-item-text"&gt;&lt;a href="#"&gt;My Profile&lt;/a&gt;&lt;/span&gt; &lt;/li&gt; &lt;li class="list-items"&gt; &lt;i class="list-item-icon far fa-gem"&gt;&lt;/i&gt; &lt;span class="list-item-text"&gt;&lt;a href="points.aspx"&gt;My Points&lt;/a&gt;&lt;/span&gt; &lt;/li&gt; &lt;li class="list-items"&gt; &lt;i class="list-item-icon far fa-calendar"&gt;&lt;/i&gt; &lt;span class="list-item-text"&gt;&lt;a href="#"&gt;My Appointments&lt;/a&gt;&lt;/span&gt; &lt;/li&gt; &lt;li class="list-items"&gt; &lt;i class="list-item-icon far fa-folder"&gt;&lt;/i&gt; &lt;span class="list-item-text"&gt;&lt;a href="#"&gt;My Drive&lt;/a&gt;&lt;/span&gt; &lt;/li&gt; &lt;li class="list-items"&gt; &lt;i class="list-item-icon fas fa-graduation-cap"&gt;&lt;/i&gt; &lt;span class="list-item-text"&gt;&lt;a href="#"&gt;My Progress&lt;/a&gt;&lt;/span&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;div class="sidebar-bottom"&gt; &lt;div class="profile"&gt; &lt;div class="profile-details"&gt; &lt;asp:Image ImageUrl="~/Images/avatar.png" ID="avatar" runat="server" /&gt; &lt;div class="name-job"&gt; &lt;div class="name"&gt;USER&lt;/div&gt; &lt;div class="job"&gt;Studet&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;i class="list-item-icon fas fa-sign-out-alt" height="34px" id="logout"&gt;&lt;/i&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="container-fluid"&gt; &lt;asp:ContentPlaceHolder ID="ContentPlaceHolder2" runat="server"&gt; &lt;div&gt;&lt;/div&gt; &lt;/asp:ContentPlaceHolder&gt; &lt;/div&gt; &lt;/body&gt;</pre></div></div><p></p></div>
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM