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