Show "<hello world>" as Text in ASP.NET RadioButton - asp.net

I want a RadioButton to display text like "<hello world>" (note I want the "<" and ">" characters to be displayed, not to be interpreted as HTML tag characters).
Tried something like this :
<asp:RadioButton ID="RadioButton1" runat="server" Text="<hello world>" AutoPostBack="True" />
but this displays no text on the browser, and renders on client side as something like :
<span class="radiobutton"><input id="ctl00_mainCopy_wizard_RadioButton1" type="radio"
... />
<label for="ctl00_mainCopy_wizard_RadioButton1"><hello world></label></span>
Any ideas ?

Try double escaping it.
&lt;hello world&gt;

Related

How to obtain a value of an input (type text) on server side in ASP.NET?

Using the HTML markup
<form id="form" runat="server">
<input id="donkey" type="text" placeholder="monkey" runat="server" />
</form>
I hoped to get the entered value in code behind by
String s = Request.Form["donkey"];
but it only produces null value. When I investigate the data structure I get something like $ctl00$main$donkey so I know it's there. After a while, I simply switched to
<form id="form" runat="server">
<asp:TextBox id="donkey" type="text" runat="server"></asp:TextBox>
</form>
but I still wonder how to reference the object from server-side if I for some reason won't switch to ASP-component.
If you want to access to the value using request.form, add name attribute to input tag and remove runat attribute.
<input id="donkey" name="donkey" type="text" />
Otherwise use
<asp:TextBox ID="donkey" type="text" runat="server"></asp:TextBox>
and on cs
string s = donkey.Text;
if you want to get value of input use like this
String s = donkey.value;
I'm not sure about ASP.net but for a regular form field to submit properly it should have a name attribute. That would be the key that you could then lookup the form value.
Just donkey.Value will return the value from text input which should have runat="server". It will create an object of System.Web.UI.HtmlControls.HtmlInputText.

How to hide items within a datalist if values are NULL (asp.net)(visual basic)

For example in my datalist if Eval("OptionJ").Tostring = Null I would like the function GetVisible to set visibility of the radio button to false like so:
<input name="Q<%#Eval("ID")%>" type="radio" value="J" visible="<%# GetVisible(Eval("OptionJ").ToString()) %>">
<%#Server.HtmlEncode(Eval("OptionJ").ToString())%>
</option><br />
I then have a codebehind function like so:
Protected Function GetVisible(ByVal Evalresult As String) As String
If Evalresult = Nothing Then
Return "False"
Else
Return "True"
End If
End Function
I have also tried checking EvalResult = String.empty
In the outputted html the visible status is being set to false...
<input name="Q3" type="radio" value="J" visible="False">
But it is still displayed on the page!
Please can you let me know how to get this working? Thanks in advance for your time reading and any answers posted.
Try this one:
<input name="Q3" type="radio" value="J" visible="false" runat="server">
Visible property works only for ASP.NET Server control but here you are using Html Input Control.
So one approach is that add runat="server" attribute in this control to if you want to continue with visible property and second one is that add style="visibility:hidden" attribute for HTML input control as given below:
<input name="Q3" type="radio" value="J" style="visibility:hidden">

How to get Custom Property from ASP.NET Textbox using javascript?

I have created a custom text box with property "key"(ASP.NET C#).I want to get the value of this property "key" using java script.How can I do this?
Not sure what you are asking.
if you have a textbox rendered like so:
<input type="text" id="foo" key="somekey" text="Hello" />
You could get the value of "key" in JS like so:
document.getElementById('foo').getAttribute('key')
If you are using jquery than for this will help you.
$("#tb1").attr("key")
for this textbox
<input type="text" id="tb1" key="mykey" text="" />

Apostrophes in XML and Databound Controls

In my XML, it's possible for an apostrophe to appear in a node's value:
<Root>
<Sections>
<SectionA>
<Heading>Title</Heading>
<Description>This is section 'A'</Description>
</SectionA>
</Sections>
</Root>
If I have controls bound to this XML:
<asp:FormView ID="myFormView" runat="server" DataSourceID="myXmlDataSource">
<ItemTemplate>
<div>
HTML Element:
<input type="text" value='<%# XPath("text()") %>' />
</div>
<div>
Server Control:
<asp:TextBox id="myTextBox" runat="server" value='<%# XPath("text()") %>' />
</div>
</ItemTemplate>
</asp:FormView>
<asp:XmlDataSource ID="myXmlDataSource" runat="server" XPath="Root/Sections/SectionA" />
I've noticed that the text is correctly displayed in the asp:TextBox but not in the INPUT element. I'm assuming that it's because server controls correctly escape the apostrophe. To work around this, I tried changing the Description node in the XML to the following:
<Description>This is section 'A'</Description>
Again, this displayed correctly in the asp:TextBox, but not in the INPUT element.
My next attempt was to wrap the node's value in a CDATA:
<Description><![CDATA[This is section 'A']]></Description>
Finally it was displaying correctly in the INPUT element, but now the asp:TextBox displayed the two "& # 3 9 ;". I've even tried "& a p o s ;" but the result is the same.
What is the best approach for the use of apostrophes in XML where the value can be displayed in either a server control or HTML element?
Here you have single quotes surrounding the value argument for the html element:
<input type="text" value='<%# XPath("text()") %>' />
This renders:
value='This is section 'A''
Instead use double quotes:
<input type="text" value="<%# XPath("text()") %>" />
Which renders:
<input type="text" value="This is section 'A'" />
Use &apos; instead. It is one of the 5 permitted entities in XML.
So your code would look like:
<Description>This is section &apos;A&apos;</Description>

for attribute - standards wise

How this code should be (asp.net standard)?
<label for="jobno">Job#</label>
<input id="TextBox_JobID" name="jobno" runat="server"/>
<input type="button" value="Show Job" class="fbutt"
id="Button_showJob" onserverclick="Button_showJob_ServerClick"
runat="server" />
</p>
<p>
<asp:Label ID="Label_error" runat="server" class="error"></asp:Label></p>
I think the for attribute is not ok, or not written in correct way?
The value of the for attribute must match the id of a form control (such as an input element or a select element), not the name.
As the textbox is marked runat="server", I would suggest using the ClientID property of the control:
<label for="<%=TextBox_JobID.ClientID%>">Job#</label>
Then if you use master pages/user controls etc, you can be sure it will always contain the right value.
It should probably read
<label for="TextBox_JobID">Job#</label>

Resources