Click here to Skip to main content
16,016,301 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.
Posted
Updated 28-Mar-11 7:45am
v2

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....

PlaceHolder1.Controls.Add(hl);


You'll need to figure the exact code but that should get you started.
 
Share this answer
 
Comments
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..
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
myCommand.Parameters.Add(paramHTML)

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.
[edit]
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
1498kbs|640x480|22000hz
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900