Note that there are some explanatory texts on larger screens.

plurals
  1. PO(ASP.NET JAVASCRIPT and C#) Hide result of javascript calling C# method
    text
    copied!<p>I am trying to hide the result of a C# method which is called from my javascript code in my aspx file. When I view the page source I want to return value, presently 'HI_MOM!', to not be visible.</p> <p>My ASPX:</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;title&gt;Hide Me&lt;/title&gt; &lt;/head&gt; &lt;body&gt;&lt;div id="center"&gt;&lt;div id="fig"&gt; &lt;script type="text/javascript"&gt; var url = &lt;%="'"+magic()+"'"%&gt;; document.write(url); &lt;/script&gt; &lt;/div&gt;&lt;/div&gt;&lt;/body&gt; &lt;/html&gt; </code></pre> <p>My C#:</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class TestTest : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } public string magic() { return "HI_MOM!"; } } </code></pre> <p>Source Code after Running:</p> <p></p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;title&gt;Hide Me&lt;/title&gt; &lt;/head&gt; &lt;body&gt;&lt;div id="center"&gt;&lt;div id="fig"&gt; &lt;script type="text/javascript"&gt; var url = HI_MOM!; document.write(url.toString); &lt;/script&gt; &lt;/div&gt;&lt;/div&gt;&lt;/body&gt; &lt;/html&gt; </code></pre> <p>Basically, I want to make it so that when I view the source code for the page the line "var url = HI_MOM!;" is not visible to the user or is masked in some way.</p> <p>EDIT: </p> <p>ANSWER: (with thanks to @Shadow Wizard for pointing me in the right direction)</p> <p>In TestTest.aspx:</p> <pre><code>&lt;script type="text/javascript" src="./jquery.js"&gt;&lt;/script&gt; </code></pre> <p>. . .</p> <pre><code> jQuery.ajax({ type: 'POST', url: 'TestTest.aspx/magic', cache: false, data: '{}', contentType: 'application/json; charset=utf-8', dataType: 'text', success: function (msg) { var result = eval('(' + msg + ')'); result = eval('('+result["d"]+')'); //do something with your string =] } }); </code></pre> <p>In TestTest.aspx.cs:</p> <pre><code>[WebMethod] public static string magic() { return "HI_MOM!"; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload