Click here to Skip to main content
14,639,650 members
Rate this:
Please Sign up or sign in to vote.
So, I have store to a database a String that include several asp tags..
Here is what I have stored..
<asp:HyperLink ID="hmembername" runat="server" NavigateUrl='<%# "friendprofile.aspx?friendid="2 %>'>John</asp:HyperLink> &#0187; <asp:HyperLink ID="hmembername" runat="server" NavigateUrl='<%# "friendprofile.aspx?friendid="1 %>'>William</asp:HyperLink><p style="padding-left: 10px;"><em> Hello......</em></p>

and I call it by using listview.
<%# Eval("post") %>

But when it triggers,it only read the html tags which is <em> or <p>.
But it doesnot parse/write the asp tags which is <asp:HyperLink>.
So, the asp tags have no effect to the output, meanwhile the html tags still have it effect to the output.
Can someone please tell me how to do parse the asp tags?
I am still new in these ASP.Net things... So, please.
Updated 28-Mar-11 7:45am
Rate this:
Please Sign up or sign in to vote.

Solution 1

You can do this form code-behind but not the way you are doing it since our sequence of events will be incorrect and the server side controls will not get rendered.

What you might do is to add a PlaceHolder control where you need to insert markup and then populate the markup form code behind in the pageload event (wrapped in a !IsPostBack) as:

Assume that the sql call returns a few string variables with the data required to fill the new control:

HyperLink hl = new HyperLink();
hl.NavigateUrl = variable_that_contains_url;
hl.Text = variable_that_contans_text_to_display;
// and so on....


You'll need to figure the exact code but that should get you started.
Cai Ming En 29-Mar-11 13:17pm
Sorry, but I do not quite get what you are trying to say..
Can you please elaborate more?
I'm still kind of new in these ASP.Net whole things..
Rate this:
Please Sign up or sign in to vote.

Solution 4

You can store the objects in a sql column, but I think you need to set the column to BLOB or XML. The reason why the em saves, and not the others, is because of the attributes in the other tags. the last double quote " was picked up as the start of the string, and the last " was the end. Thus em and p was saved.

So you need to use a parameter to store the character array
Update table set html=@html
eg parameter 
Dim paramHTML As SqlParameter
paramHTML = New SqlParameter("@html", SqlDbType.blob)
paramHTML.Value = sHTML

But on the downside, you can extract them, but I don't see how you can reconstitute them back into html objects on your web page.

The objects need to be read by the server, so they can be converted into html, and sent back to the browser for decoding.

You may want to consider storing plain html in the database instead.
You may want to consider html encoding the string before saving, and decoding during extraction.

Overall in the end, storing html in the database is a bad idea. I tried it once, and dealing with the " and slashes in the end, was more trouble then it was worth. So I went with a large parameter array, and just did a split to separate them back out

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100