I need to URL encode an email address. If I do this (without URL encode), it works:
<!DOCTYPE html>
<head>
<title>Test</title>
</head>
<body>
<a href="https://www.example.com/reset-password?e=%7bEMAILADDRESS%7d">
</body>
</html>
The email address is printed raw, not URL-encoded.
What I'd really like to do is the following, but HttpUtility.UrlEncode() doesn't execute:
<!DOCTYPE html>
<head>
<title>Test</title>
</head>
<body>
<a href="https://www.example.com/reset-password?e=HttpUtility.UrlEncode("%7bEMAILADDRESS%7d")">
</body>
</html>
Any suggestions on how to execute HttpUtility.UrlEncode() for usage in the above manner? Thanks for any help.
You need to use <%= %>
like:
<a href="https://portal.nchinc.com/reset-password?e=
<%=HttpUtility.UrlEncode("%7bEMAILADDRESS%7d") %>"/>
The <%= ... %> is used when you need to display an expression.
Related
I am generating pdf from this HTML, and for achieving this I am using https://www.nrecosite.com/pdf_generator_net.aspx
This is the HTML
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<div>
<p>Remarks</p>
<p>한국어 발언을 표시하는 테스트입니다</p>
</div>
</body>
</html>
and this the code for generating the pdf:
var pdfBytes = new
NReco.PdfGenerator.HtmlToPdfConverter().GeneratePdf(html);
and the result is this:
how can I generate the pdf with the correct Korean utterances?
Thanks
I want to format html code with C#.
From this:
<!DOCTYPE html><html><head><title>Hello World!</title></head><body><h1>Hi, HTML!</h1></body></html>
I want this:
<!DOCTYPE html>
<html>
<head>
<title>Hello World!</title>
</head>
<body>
<h1>Hi, HTML!</h1>
</body>
</html>
I tried:
string result = System.Xml.Linq.XElement.Parse(source).ToString();
And this works, but if I try this with Google website code, it throws some exceptions because
doctypeisn't written correctly.
How can I format HTML code without HTML syntax error check?
Can anyone help me? Thanks in advance!
I want to create a tag prefix for controls in System.Web assembly.
<%# Page Language="C#" CodeBehind="SimpleCustomControl.aspx.cs" Inherits="SimpleCustomControl" %>
<%# Register TagPrefix="CC" Namespace="System.Web.UI.WebControls" Assembly="System.Web" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<CC:TextBox runat="server"></CC:TextBox>
</div>
</form>
</body>
</html>
But getting "Unrecognized tag prefix or device filter CC. Can not resolve symbol CC" error in VS. And no autocomplete is available after entering <CC:.
Is it possible to register such kind of tag prefix for standard controls?
I have a page that has the conditional comment:
<%# Page language="c#" %>
<html>
<head>
<title>ASP.NET Application</title>
<!--[if lt IE 8]><script type="text/javascript" src="scripts/json_parse.js"></script><![endif]-->
</head>
<body>
test
</body>
<html>
When I do it like above, it throws a compilation error saying it expects a closing "script" tag. But the below code (which should end up with the same page) works perfectly:
<%# Page language="c#" %>
<html>
<head>
<title>ASP.NET Application</title>
<!--[if lt IE 8]>
<% Response.Write( "<script type=\"text/javascript\" src=\"scripts/json_parse.js\"></script>" ); %>
<![endif]-->
</head>
<body>
test
</body>
<html>
Why does it have a problem with IE conditionals? The script tag is inside a comment and is not "runat".
This is a case where you want the conditional comments to be revealed to downlevel browsers, not hidden by uplevel browsers, so there is a slightly different syntax to use:
<![if lt IE 8]>
<script type="text/javascript" src="scripts/json_parse.js"></script>
<![endif]>
See this MSDN article for detailed information.
Does anyone have any samples of injecting a HTML snippet just after the open BODY tag in an ASP.Net webforms page? The positioning of this code is very specific.
The beginning HTML might look like this:
</head>
<body>
<div id="header">
The resulting HTML should look like this:
</head>
<body>
<div id="new-div"></div>
<div id="header">
This is a scenario where the HTML cannot be manipulated directly, and javascript would do this too late for the additional HTML to be useful. It must be done with server-side code and in place before the HTML makes it to the web browser.
You can do it this way in your aspx markup:
<html>
<head>
</head>
<body>
<%= FunctionTheOutputsString() %>
The <%= is short for Response.Write(), which is a function that writes directly into the page.
With jQuery, you can use prepend() as so:
$(function(){
$('body').prepend('<div id="new-div">Div content</div>');
});
jsfiddle here.
Update: The server-side solution could also be (besides above answer):
<html>
<head>
</head>
<body>
<asp:placeholder id="divPlaceHolder" Visible="False" runat="server">
<div id="new-div">
</div>
</asp:placeHolder>
On Page_Load()...
if(SomeCondition)
divPlaceHolder.Visible=true;
And because non-visible elements aren't rendered, the new-div element will only be displayed if SomeCondition is true