How to render a piece if ASP.NET code into HTML?

P

Przemo

Hi,

In classic ASP I was able to do something like:
<title><%=MyVariableWithTitle%></title>

How to do the same in ASP.NET using VB.NET?

thank you!

Przemo
 
T

Teemu Keiski

Hi,

for example put Literal control on the header between <title> tags and set
its Text property to the text you want to display in the title. Another
alternative is just to put the <title> tag with an ID and runat="server"
attributes and then set innerHtml/innerText property programmatically.
Result is the same
 
K

Ken Cox [Microsoft MVP]

Here's one way...

<%@ Page Language="vb" AutoEventWireup="True" %>
<script language=vb runat=server>
public MyVariableWithTitle as string
Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
MyVariableWithTitle = "Page Title"
End Sub
</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title><%= MyVariableWithTitle%></title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
Hi Przemo
</form>
</body>
</HTML>

Does this help?

Ken
Microsoft MVP [ASP.NET]
Toronto
 
G

Guest

Thank you!
I wanted to use your idea for another case, but it
doesn't work.
In this case I would like to insert value determining
time of timeout.

<SCRIPT LANGUAGE="JavaScript">
<!--
function refresh_window() {
setTimeout
('window.location.href="SamochodyCzekajace.aspx"',
<asp:Literal id="Literal1" runat="server"></asp:Literal>);
}
//-->
</SCRIPT>

Przemo
 
G

Guest

Yes it helped!
It is so trival...
But I have another similar problrm, with programatic
inserting some value into html as a part of JavaScript.
I have sent example for this newsgroup few minutes
earlier as a replay for my first post.

Przemo
-----Original Message-----
Here's one way...

<%@ Page Language="vb" AutoEventWireup="True" %>
<script language=vb runat=server>
public MyVariableWithTitle as string
Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
MyVariableWithTitle = "Page Title"
End Sub
</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title><%= MyVariableWithTitle%></title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
Hi Przemo
</form>
</body>
</HTML>

Does this help?

Ken
Microsoft MVP [ASP.NET]
Toronto

Przemo said:
Hi,

In classic ASP I was able to do something like:
<title><%=MyVariableWithTitle%></title>

How to do the same in ASP.NET using VB.NET?

thank you!

Przemo

.
 
T

Teemu Keiski

Make it another way. Create a Literal to which output the complete script or
optionally use Page.RegisterClientScriptBlock and or
Page.RegisterStartupScript methods for registering scripts.

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top