Multi language: asp:label aganist html:label with asp:Literal - asp.net

I'm adding multi language support to a prototype web site. The site was developed using html lables which I could multilanguage using asp:literal or I could change them all to asp:labels as shown below.
<asp:label ID="lblAddress1" runat="server" Text='<%$ Resources:lblAddress1 %>' /></br>
<label><asp:Literal ID="Literal1" runat="server" Text="<%$ Resources:lblAddress1 %>"></asp:Literal></label>
Web stuff isn't my area of expertise and the guys here don't think there is any advantage one way or the other. What would you choose and why?

<asp:Literal>
Use this control as a placeholder for any text you wish to insert in the page. The output will not be wrapped in any html markup tags (simplest).
<asp:Label>
Use this control in the same way as the , however, This control will wrap the text in html tags. These span tags allow the control to have additional properties (css styling etc.) which can be leveraged.
<label>
This html tag has semantic value in a page and is used to associate form elements with their description.
<label for="SaveLoginName">Remember Me:</label>
<input type="checkbox" id="SaveLoginName" />
A browser can use this info to provide additional accessibility features such as enabling clicking text to toggle checkbox value.
Each of these have appropriate usage scenarios.

Seems to be a matter of taste. Although I think the second option may add a little weight to the page because literals are usually wrapped in <span>

Related

ASP:TextBox convert into bootstrap <input>

I've got a styling question on my hands. Using sensenet, a platform for ASP.net functionality, forms are done with not only sensenet language, but also ASP.net language as well.
I'm having a problem making the ASP:TextBox feature look like the bootstrap input box. I've called the bootstrap css file, tried changing the class for the ASP:TextBox code, but nothing works aside from just using the html tag of
<input class="text input-sm">
Here's the code I have so far:
<asp:TextBox CssClass="text input-sm" ID="InnerControl" placeholder="Middle Name" runat="server"></asp:TextBox>
.. and the css is being incoporated here:
<sn:CssRequest CSSPath="$skin/styles/Projectname/bootstrap.min.css" ID="pageTemplateUIStyleReq1" runat="server" />
Is there anyway to make the ASP:TextBox to look like the bootstrap input box but also function the way it's meant to function through ASP language?
Attached are images of the before and after-sought effects:
what I have now:
what I'm looking to attain:
The way you are adding the class to your textbox is correct. The problem is here:
<sn:CssRequest CSSPath="$skin/styles/Projectname/bootstrap.min.css" ID="pageTemplateUIStyleReq1" runat="server" />
Just add a normal reference to your stylesheet and don't try to load it server side. If your page requires this, check to ensure it is loading bootstrap correctly in your browsers dev tools.

asp.net login and register user controls formatting

I have a VS2010 C# web application with standard login and register controls.
The login/register template is generated as below.The problem with this is that the label and the text field are displayed in 2 lines. But I would like to display them in single line with proper alignment . All label text right aligned with each other etc. I tried by CSS but I cannot assign length to inline elements. I can try converting everything to block elements and assigning width,float. But I am wondering if there is any option to generate table layout without too much CSS fiddling.
<p>
<asp:Label ID="UserNameLabel" runat="server"
AssociatedControlID="UserName">User Name:</asp:Label>
<asp:TextBox ID="UserName" runat="server" CssClass="texdtEntry"></asp:TextBox>
</p>
Just Convert to Template and change it:
How to: Use Advanced Features of the ASP.NET Login Control

Why does AjaxControlToolkit TabContainer render all custom control markup properties?

This is a strange one to explain but hope I make sense.
Our organisation has a library of custom controls that we use in our solutions. One example of these controls is a textbox combined with a set of validators which can be configured appropriately by its properties set in the markup.
I now have a problem when using this control in (which I beleive to have narrowed it down) a TabContainer.
If I wanted to use the following markup in the container:
<scc:TextBox ID="txtEmailAddr" runat="server" CssClass="input EmailAddress" EnforceEntry="EmailAddress"
ErrorMessage_RequiredFieldNotCompleted="" ErrorMessage_ShowExclamation="true"
MaxLength="150" ShowErrorMessageBelow="false" Label="Email Address " />
When I save or reload the .aspx markup it then renders the following markup for the same control:
<scc:TextBox ID="txtEmailAddr" runat="server" CssClass="input EmailAddress" EnforceEntry="EmailAddress"
ErrorMessage_RequiredFieldNotCompleted="" ErrorMessage_ShowExclamation="True"
MaxLength="150" ShowErrorMessageBelow="False" Label="Email Address "
ClientSidePreventInvalidChars="True" EnableClientScript="True"
EnfoceOnPaste="False" EnforceMaxLengthWithRXOnMultiline="True"
EnforceOnPaste="False" EnforceSpaceInPostcode="True"
ErrorMessage_InvalidFormat="Email Address : Please enter a valid email address"
ErrorMessage_NumericValueInvalidOrOutOfRange="Email Address requires a number to be entered in the range to ."
GuidanceText="" GuidanceText_RenderInMouseoverPanel="False"
JavascriptURL="~/Include/TextBoxMaximumLength.js" LabelBold="False"
LabelCSSClass="" MaxValue="9999999" MinValue="-9999999" Read_Only="False"
RememberAnswer="False" RenderInParagraphs="True"
RenderRequiredTextForRequiredFields="True" Required="True"
RequiredField_InitialValue="" Rows="0" ShowMaxLength="False" Text=""
TextBox_TabIndex="0" TextboxSkinID="" TextMode="SingleLine"
TooltipPopup_BodyText="" TooltipPopup_TooltipText="(guidance)"
ValidationGroup="" ValidationExpression="" />
This would not be a problem other than the properties that are now being rendered in the markup are overriding default functionality of the actual control. In this case the default Email Address regular expression is being ignored because the property 'ValidationExpression' is being set to an empty string!
Again I could place the default regex in that property, but I would just like to understand why the markup is behaving in this manner?
Thanks.
Get the code for the AjaxContolToolkit and step through it to see why all properties are rendered. You can adjust that code as you need and compile the dll and use that. From personal experience, that is the only way I have found use for the Toolkit because of behaviors like you describe.

'ImageButton' must be placed inside a form tag with runat=server

I've got the ImageButton wrapped inside a form tag with runat="server" but STILL getting this error at runtime. The form tag is at the very beginning (before my table) and end tag is at the end (after the table).
<td>
<div>
<div id="pay-Button"><asp:ImageButton ID="PayButton" ImageUrl="<%=PayButtonImageUrl %>" OnClick="RedirectTest" runat="server" /></div>
</div>
</td>
You can't have managed controls within a <form> tag without the runat='server'. ASP.Net supports multiple form tags, but with only one of them having a server-side designation. Also, I don't believe that HTML supports nested forms. You'll either want to have it be a non-managed control in a separate form or remove the nested <form> tag from the server-side form.
Look here for further explanation.
remove the ImageUrl="<%=PayButtonImageUrl %>" part, I don't believe you can use those inline snippits for server control properties (unless you're databinding)
Does your tag also have
runat="server"
as an attribute?
It would be helpful if you showed more of your code so we can help.

What's the Literal control used for and what's the difference to the Label Control in asp.net?

What Literal control is used for in asp.net? and What is the difference between them and Label control?
The major difference is that the Label Control adds the span tag to the text (property) you set, allowing to apply a style to it:
<span>My Label text</span>
The Literal Control allows you to render any kind of content. You can use it to render scripts, hmtl and any other type of document content. It doesn't change the string you provide in the Text property.
Note: the Label control allows you to render straight HTML too, but it puts all your text in span tags as mentioned. So, for rendering large HTML portions a Literal control is the way to go.
P.S.: In HTML there is a <label> tag. If you use the AssociatedControlId property of the Label control, it will render as HTML <label> (thanks to Ray for pointing that out.)
For example:
<asp:Label runat="server" id="FirstNameLabel" AssociatedControlId="FirstNameTextBox">
Input First Name:
</asp:Label>
<asp:Textbox runat="server" id="FirstNameTextBox" />
Will render as:
<label for="FirstNameTextbox" id="FirstNameLabel">Input first name:</label>
<input type="text" id="FirstNameTextbox" name="FirstNameTextBox" />
See also here on W3 Schools.
One thing also to note is if you are justing using it to display something and have no need for formatting the text use a Literal control. The ViewState is not as heavy with a Literal vs a Label control and when you have many of these on a page using ViewState it can really bloat your page size.
I always ask myself, do I need to apply a custom style or formatting? Yes, use a Label. No, use a Literal.
It is used to display text on the page, the text that is displayed can be set at runtime via server side code.
The label control also has the AssociatedControlId property that associates the label with another control. An example of where this is useful is with a textbox control. Once these are associated, screen readers are more able to give better results.
Another example is a radio button with a label allows you to click on the label and the radiobutton will select if the AssociatedControlId property is set.
MSDN on AssoicatedControlId
As splattne mentions, the label encloses its text in a span, whereas the literal is simply a placeholder. However, be careful in making assumptions about how ASP.Net controls are going to render. It can depend on the user agent that you are using. For instance, the panel control renders as a div in IE, but renders as a table with Firefox.
It will place LITERALLY whatever text you place in it on the page. You can use it to write html, JavaScript or just plain text.
We can use literal control in the title tag whereas label cannot be used in the title tag
Label can be used to set focus on other controls like Textbox.
Whereas Literal simply rander the static text on the web page

Resources