Reputation: 51937
On my page, there's an HTML button and I want to set its value in C# using a literal; something like this:
<input type="button" value="<asp:literal runat="server" ID="Dico" />" />
This doesn't work because the quotes clash in the aspx markup.
How can I set the value of a button with a literal?
Note: for now, I just have the literal that writes the entire HTML markup of the button, like this:
Dico.Text = "<input type=\"button\" value=\"" + SomeValue + "\" />";
This works because the literal creates the button and sets its value at the same time. But what I want is to use the literal just for the value of the button.
Upvotes: 1
Views: 1323
Reputation: 2490
You need to use single quotes for Value
<input type="button" value='<asp:literal runat="server" ID="Dico" />' />
If you still want to use Value in Double quotes you must use runat
and ID
of literal in single quotes
<input type="button" value="<asp:literal runat='server' ID='Dico' />" />
Upvotes: 1
Reputation: 56688
First of all, kudos for using Literal
control!
Quotation problem is easy to fix, as you can use single quotes for html tag attributes:
<input type="button" value='<asp:literal runat="server" ID="Dico" />' />
However you can just as easy turn the input
into server-side control by simply adding runat="server"
and manipulate its properties ad attributes directly in code behind.
Upvotes: 1