dachizzle37
dachizzle37

Reputation: 49

Create HTML Tags in ASP.Net Web Pages

So, I am building a blog that will sometimes include code for demonstrating basic number theory algorithms, and sometimes images of different food dishes. I am using ASP.Net Web Pages. I am stuck on figuring out how to display blog as html, because the order of writing, code and images will vary. For instance, do we store the blog complete with tags and read directly into: <%=GetBlog()%> or store the blog with home made tags and parse them, then create some kind of loop using: <%...%> I really like the format of this site where we can enter writing

and code and images Is there a pattern that is ideal for achieving what I have described?

Upvotes: 0

Views: 790

Answers (1)

Daniel Manta
Daniel Manta

Reputation: 6683

For example in your C# code behind:

protected void Page_Load(object sender, EventArgs e)
{
    this.Literal1.Text = "my paragraph here";
    this.Image1.ImageUrl = "http://simpleicon.com/wp-content/uploads/smile.png";
    this.Image1.Height = 20;
    this.MyCodeControl.InnerText = "my code here";
}

In your .aspx file you have:

<p><asp:Literal ID="Literal1" runat="server"></asp:Literal></p>
<asp:Image ID="Image1" runat="server" />
<code id="MyCodeControl" runat="server"> </code>

Since an Internet browser doesn't understand Asp nor C#, this code runs at server and becomes into this Html:

<p>my paragraph here</p>
<img id="Image1" 
     src="http://simpleicon.com/wp-content/uploads/smile.png"
     style="height:20px;" />
<code id="MyCodeControl">my code here</code>

I don't know what server side control generates code and p Html tags, so I have added ordinary Html tags with runtat="server" attribute. This allows me to access to the control in C# code behind.

Also check out how to use more complex controls like Repeater and ListView.

Upvotes: 1

Related Questions