Tuesday, March 13, 2012

So .Net doesnt support Page Render functions?

Which leaves me a lot of questions...

How am I meant to bypass a whole chunk of HTML if I can't use the ASP.Net equivalent of <%=%> and including output responses?

For instance... on one of my pages, I have this:

<div id="DocumentBody">
<% If Request.Form("to") <> "" Then %>
<div id="DocumentBodySent"
<p>Your message was sent to <%=Request.Form("to")%> successfully</p
</div>
<% Else %>
<div id="DocumentBodyForm"
<form action="<%=Request.ServerVariables("script_name")%>"
<input type="text" name="to" />
<!-- and loads of other typical email form inputs -->
</form>
</div>
<% End If %>
</div
How would I do this in ASP.Net?

I also note that Microsoft's samples of ASP.Net code use Response.Write to give out HTML code with the quotes for attribute values ommitted, but this is baaaad HTML, (all my stuff is XHTML 1.0 Strict anyway) and I don't want to have to do "&Chr(34)&" every time I have to include a double-quote in a tag.

So then... how?

Peace out
-W3bboUse your code behind...

<div id="DocumentBody">
<% If Request.Form("to") <> "" Then %>
<div id="DocumentBodySent"
would translate to:

[code]
*.aspx page would have
<div id="DocumentBody">
<asp:Panel
id="someKindOfPanel"
runat="server"
style="anyStyleYouWant"
visible="false"
/
*.aspx.cs page would have
<script language="C#" blah blah blah blah >
if (to.Text <> "")
{
someKindOfPanel.Visible = true;
}
[/code]

Hope this helps.
As for the Quote in a programmatically defined string, I recently discovered that you can use 2 double quotes side by side to replace the "&Chr(34)&"

Example:
Dim strJavaScript as String = "<script language=""Javascript""> ect..."

it's weird at first, but it is nicer looking than adding the chr(34)s everywhere

0 comments:

Post a Comment