Localization html static text [duplicate] - asp.net

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
asp.net globalization difference in inline tags
I read on MSDN about localization of static text and Localize control but I still don't understand: how should I localize for example a html table's static text?
<table>
<tr>
<td>
<%=Resources.Resource1.String1 %>
</td>
</tr>
<tr>
<td>
<%=Resources.Resource1.String2 %>
</td>
</tr>
</table>
or
<table>
<tr>
<td>
<asp:Localize ID="Column1" runat="server" Text="<%$ Resources: Resource1, String1 %>" />
</td>
</tr>
<tr>
<td>
<asp:Localize ID="Column2" runat="server" Text="<%$ Resources: Resource1, String2 %>" />
</td>
</tr>
</table>
The first is obviously is more readable and I don't need to change translations on runtime. Maybe it has some disadvantages vs second? I'm sorry for my stupid question but I want to be sure that way which I'll select will be more preferable and maintainable.

The examples you showed do not really make any difference. The first one will be easier to code - you will see IntelliSense (code completion) hint.
Personally I prefer Implicit Localization for it will give you defaults and I feel the code is less cluttered:
<table>
<tr>
<td>
<asp:Localize ID="Column1" runat="server" meta:resourcekey="Column2" Text="Column 1 name" />
</td>
</tr>
<tr>
<td>
<asp:Localize ID="Column2" runat="server" meta:resourcekey="Column1" Text="Column 2 name" />
</td>
</tr>
</table>
Also, I find App_LocalResources to be a better way for Localizing Asp.Net applications - you would need to split your translation into several .resx files, which might be just easier to maintain in large code base (for example it would be easier to use Translation Memory software; it should cost less).
For more information on Implicit Localization, see my previous answer.

The second one will give you a Control whose ID you can reference from code to change on the fly. The first one does not have this ability. For example:
if (condition)
Column1.Text += " - 123";
else
Column1.Text += " - 456";

Related

How to create excel kind of filter, sorting, edit data in asp.net?

I want to allow 20k data records in asp.net to filter, sort, paging and edit. Which is the best possible?
Well, as noted, we can't load 20k records at one time - that would be too much data for a use at one time.
So, can you add paging and say display a screen of data in grid/table like view? yes, that's easy.
Can you add sorting to the grid display (say sort up/down) Yes, it will take a wee bit of code, but that can be done quite easy.
But to allow say the user to filter on any column? Hum, that going to take quite a bit of work. So you can certainly acheive the first two goals - quite easy.
but there not any built in filter system + set of controls that will acheive the filtering options for you. I REALLY wish there was. You can consider some 3rd party controls - they are quite expensive, but they do look very nice. So, say this grid from telerick is a great example of what you looking for:
So the above has paging, and sorting, and filters.
demo here:
https://demos.telerik.com/aspnet-ajax/grid/examples/overview/defaultcs.aspx
I REALLY don't know why after all these years that the base .net package does not include a grid extender or a listview control that is so feature starved, that everyone every day has to go out and re-invent the world.
But then you have to work to add a data pager And out of the box, the default format for the pager does not look all that great. Once you spend a hour or two, you can get a nice formatted data pager (but it should not be that much work to get a nice look and feel out of the box - it just should not be).
So say here is a listview (I used the wizards - then deleted 99% of the markup, and with this markup:
<asp:ListView ID="ListView1" runat="server" DataKeyNames="ID">
<ItemTemplate>
<tr style="">
<td><asp:label ID="FirstName" runat="server" Text='<%# Eval("FirstName") %>' /></td>
<td><asp:label ID="LastName" runat="server" Text='<%# Eval("LastName") %>' /></td>
<td><asp:label ID="HotelName" runat="server" Text='<%# Eval("HotelName") %>' /></td>
<td><asp:label ID="City" runat="server" Text='<%# Eval("City") %>' /></td>
<td><asp:CheckBox ID="Active" runat="server" Checked='<%# Eval("Active") %>' /></td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table id="itemPlaceholderContainer" runat="server" border="0" style="">
<tr runat="server" style="">
<th runat="server">FirstName</th>
<th runat="server">LastName</th>
<th runat="server">HotelName</th>
<th runat="server">City</th>
<th runat="server">Active</th>
</tr>
<tr id="itemPlaceholder" runat="server"></tr>
</table>
</LayoutTemplate>
</asp:ListView>
And it looks like this:
So the listview is a nice way to present the data.
However, to get a nice layout, nice filtering, a half decent looking datapager? It takes a truckload of work. The out of the box asp.net controls used to be perhaps the BEST feature of asp.net
That above page was created by me in less time to write this post. It looks not bad - but "not bad" was 5 or 10 years ago.
The new data controls out of the box should be like the first grid - the amounts of efforts to obtain a nice looking grid IMHO is just not all that great right now.
So, I would consider a 3rd party grid control, or you going to have to learn quite a bit of css to get a great looking Excel like display.
It is possible. My beters would be for simple - gridview.
But, for really nice layout - extra options - go with listview - it requires a bit more markup, but has near unlimited flexbility.

ASP.Net Repeater from Entity Framework (Webform Markup)

I'm having problem finding information on selecting data from an Entity Framework entity from within the markup of an ASP.Net Repeater
I have a Repeater like this:
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="s_Options">
<HeaderTemplate>
<table>
<tr>
<th>Manager Name</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><% !!!!! MY PROBLEM IS HERE %></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
And I have an Entity called Option.
Option has 3 members:OID, Option_Type, and Option_Value
I am trying to populate this repeaters with Option_Values where Option_Type = "This Option" but I am completely lost on how to do this in the item template and I am having trouble wording my question correctly to find answers to it elsewhere.
First of all, if doing this in the markup for the Repeater is not the best way, please let me know.
Additionally, I am looking for any help on how to filter this entity and how the markup looks.
Also, if this is something that has been covered somewhere else, then I apologize, I must be asking the question incorrectly. If you could help me articulate what I'm asking in a more constructive way, please let me know.
If I understand you question correctly, you want -
<ItemTemplate>
<td><%# Eval("Option_Type") %></td>
</ItemTemplate>
Take a look at the bottom of Displaying Data with the DataList and Repeater Controls article.
Use this code and put your table column name in Eval..
<table style="width: 400px">
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<tr>
<td>
<asp:Label ID="LBLtEXT" runat="server" Text='<%#Eval("Your filed name ")%>'></asp:Label>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>

Load data into a UserControl as control properties or in control code behind?

I'm building a UserControl that will repeat on the page a variable number of times. I'm trying to determine what the most efficient way to handle the data I will be loading into the Control. For the sake of simplicity, lets say it will be structured something like this:
<table>
<tr>
<td>Header Item</td>
</tr>
<tr>
<td>Body Item n</td>
</tr>
<tr>
<td>Body Item n+1</td>
</tr>
<tr>
<td>Body Item n+2</td>
</tr>
<tr>
<td>etc.</td>
</tr>
<tr>
<td>Footer Item</td>
</tr>
</table>
All of the data that will be loaded into this Control will come from a SQL Query. The Body items will be changing on every iteration of the control, but the Header and Footer items will be the same, and that is where I am trying to decide between a couple of options I can see.
Build the query into the code behind of the control itself and repeat it for every iteration of the control, or:
Query the data from the .aspx.cs page where the control will be used and deliver them as properties when the control is created.
?
Option 1 seems very inefficient. If we were talking about only two items, then I might just be inclined to accept the inefficiency, but we're talking about a lot more.
Option 2 seems plausible, but I have no idea if that is actually any better than option 1.
Thoughts? Other options?
Use a Repeater control
Have a look here:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.repeater(v=vs.80).aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-1
<asp:Repeater runat="server">
<HeaderTemplate>
<table>
<tr>
<td>Header Item</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>Body Item <%# Eval("Number") %></td>
</tr>
</ItemTemplate>
<FooterTemplate>
<tr>
<td>Footer Item</td>
</tr>
</table>
</FooterTemplate>
</asp:Repeater>

Increment control ID in ASP.NET WebForms automatically

I have a huge ASPX web form which has around 100 fields which need to be input fields. This web form is an excel sheet converted into to an HTML Page.
I have marked table cells which need to be input fields with a string "txtb" (TextBox).
Once I was done with the look and feel, I tried replacing all txtb string with <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> thinking that the ID=TextBox1 will be incremented automatically by the editor itself, like TextBox2, TextBox3 and so on.
But all the replaced txtb strings show <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> only.
I know that if we copy <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> and paste manually inside the editor, the editor will increment the id by 1 for each paste.
How can I get this to happen for automatic replace? Please help.
<tr>
<td colspan="2">
txtb
</td>
<td>
txtb
</td>
<td>
txtb
</td>
<td>
txtb
</td>
</tr>
<tr>
<td colspan="2">
txtb
</td>
<td>
txtb
</td>
<td>
txtb
</td>
<td>
txtb
</td>
</tr>
It is just some huge file that looks like this. I want to replace each txtb instance with <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>, but the ID should be incremented on each replace. I wish PowerShell was installed on this machine. Otherwise I could have scripted this. Since there is not much time and no other way I can think of, I am posting here for help.
I would recommend this library and query your page for 'txtb' tags and replace them with textboxes. You can count the number of 'txtb' occurences and append them to the ID attribute of your dynamicly created textbox.
http://htmlagilitypack.codeplex.com/
See this links for some examples:
http://htmlagilitypack.codeplex.com/wikipage?title=Examples
Does this help you?
I think the editor will take care of IDs if you first replace the txtb with
<asp:TextBox id="TextBox" ... />
in the Excel itself and then copy/paste it into the editor.

Form Post Values using plain html controls in ASP.NET web forms

I have a simple form with some plain html input like bellow using ASP.NET Web Forms (not MVC)
<table id="tbl_SchoolDetails">
<tbody id="tbody_SchoolDetails">
<tr>
<td>
School Name
</td>
<td>
<input id="SchoolDetails_SchoolName" type="text" value="<%= ViewModel.School.Name %>" />
</td>
</tr>
<tr>
<td>
Head Teacher
</td>
<td>
<input id="SchoolDetails_HeadTeacher_Name" type="text" value="<%= ViewModel.School.HeadTeacher.Name %>" />
</td>
</tr>
<tr>
<td>
Head Teacher Email
</td>
<td>
<input id="SchoolDetails_HeadTeacher_Email" type="text" value="<%= ViewModel.School.HeadTeacher.Email %>" />
</td>
</tr>
<tr>
<td>
Regent/Placement Contact
</td>
<td>
<input id="SchoolDetails_Regent_Name" type="text" value="<%= ViewModel.School.Regent.Name %>" />
</td>
</tr>
</tbody>
</table>
When I do a post back to the server the values of the text boxes are not contained in the Request.Form element. Is there some reason for this that I am missing. I am reluctant to use asp.net controls as the page is later going to require a fair amount of javascript for changing the ui and other stuff.
I know I could easily do this with MVC but unfortunatly a change to this is not an option at this time.
Cheers
Colin G
Give the input both an id and a name and see if that doesn't solve your problem.
<input id="SchoolDetails_SchoolName"
name="SchoolDetails_SchoolName"
type="text"
value="<%= ViewModel.School.Name %>" />
The id property only identifies the tag within the DOM. The name property allows the tag to be posted back as part of a form. An ASP.NET control, or an HTML element with runat=server, automatically gets both the name and id properties assigned.
HTML elements are not part of the ASP.NET lifecycle. An easy way to start would be to add the runat="server" attribute to your INPUT elements.
#tvanfosson Cheers that worked just as I wanted.
#Bullins I really didn't want to use runat="server" as it causes the ID's of the controls to end up like ctl00_ContentPlaceHolder1_ctl00_SchoolDetails_Address_Postcode which makes it difficult to achieve what i am looking for.
#Colin Use ClientIDMode="Static" attribute and your server-side element name will remain the same on the client side even when you have runat="server" on the element. Hope this helps

Resources