How to make multilinguage link text li menu and dropdownlist? - c#

I cannot post my code but I want to know how I can write in resource file and other the link text in masterpage like and dropdownlist multilinguage in asp.net c# website.i need to use global app.global resources due to my desire to localize it in many languages to handle the files.i will be happy if you show me in asp.net website only i do not have much knowledge in mvc and web application and moreover what i started to do is in asp.net website.
<li>Buy</li>
<li>Rent</li>
<li>Estimate</li>
<% if (Session["user"] == null)
{ %>
<li>Sell</li>
<% }
else
{ %>
<li>Sell</li>
<%} %>
<asp:ListItem>Select the Category</asp:ListItem>
<asp:ListItem>Villa</asp:ListItem>
<asp:ListItem>Apartment and Condos</asp:ListItem>
<asp:ListItem>Farm</asp:ListItem>
<asp:ListItem>Office</asp:ListItem>
<asp:ListItem>Store</asp:ListItem>
<asp:ListItem>Storey House</asp:ListItem>
<asp:ListItem>Plot</asp:ListItem>
<asp:ListItem>Shop</asp:ListItem>
<asp:ListItem>Other commercial</asp:ListItem>
</asp:DropDownList>

Add resource files for the different languages, e.g. LocalizedText.resx (fallback language), LocalizedText.fr.resx (french), LocalizedText.de.resx (german), etc.
Add keys and values for the texts to be translated to these resource files, e.g. Villa, ApartmentAndCondos.
Then ASP.net will resolve the correct language version of the resource file to be used based on the language sent by the browser.
<asp:ListItem><%$ Resources:LocalizedText, Villa %></asp:ListItem>
<asp:ListItem><%$ Resources:LocalizedText, ApartmentAndCondos %></asp:ListItem>
You can use the <%$ Resources:{FileName}, {ResourceKey} %> command anywhere to return translations. E.g. in a link:
<%$ Resources:Resources:LocalizedText, Sell %>
See Walkthrough: Using Resources for Localization with ASP.NET.

Related

Making a asp.net web site template without using master page?

I am very new to asp.net and my job.
I was assigned a project to make a simple online order web application using asp.net c#.
The specification has been strictly defined (copied below)
Regarding the common content of the site, I need to make head, top and left(a search function)
"The design in /design/: Head.aspx Top.aspx Left.aspx"
-- Does that mean I am not allowed to use (nested) master page?
--- If so, how can I make a template without using master page?
Another option is to use the Server.Execute() method to render the contents of three separate pages into your base page if you have to use pages instead of usercontrols and still must have three separate pages rendered into one.
In the old days we did this with iis html includes.
If the head/top/left content is just basic HTML, then you could just put the HTML in a separate file and use an include link/reference in the original .aspx page.
If the content is all like a search function, then I agree with Henk's comment, create an .ascx User Control (which is really no different than an .aspx page with an .ascx extension) and then just reference that control on your .aspx page like this:
//put this at the top of your .aspx page
<%# Register src="usercontrols/YourControl.ascx" tagname="nameOfControl" tagprefix="ucControlName" %>
//then reference your control where you want it in your .aspx page
<ucControlName:nameOfControl ID="nameOfControl" runat="server" Visible="True" />
Here's an MSDN article on creating user controls: MSDN User Control
Maybe shoot the person who wrote the spec an email and ask why they have an issue with using a master page - this is kind of exactly why you would use one?!
JM

Detect asp:FileUpload has a file using Jquery?

I am using asp.net file upload
<asp:FileUpload ID="ImageUploader" runat="server"/>
how can i detect that asp:FileUpload has a file using Jquery?
I am doing this
$("#ctl00_MainContentPlaceHolder_UCUpdOrgProfile1_ImageUploader").change(function (e) {
alert("hello")
});
But i dont know either file is selected or not.
check -
if (document.getElementById('<%= ImageUploader.ClientID %>').files.length === 0)
{
// File upload do not have file
}
else {
// File upload has file
}
Valid answers, or since ASP 4+ just set ClientIDMode as a page property:
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" ClientIDMode="Static" %>
The ClientID value is set to the value of the ID property. If the control is a naming container, the control is used as the top of the hierarchy of naming containers for any controls that it contains.
- reference
ie. this will force ASP to obey the ID as declared and not generate the "ctl00_" prefix or any other.
This is awesome as it is applied to the whole page and all asp controls contained on it, no extra code, no hacks just one awesome property.
So apply the same logic as #Microsoft_DN solution, but use static ID's.

manipulating .aspx file programmatically

I was recently assigned a task of changing our asp.net web site localization to use custom resource provider (using sql database) instead of the default asrx resource files. Right now I'm chalenged with replacing hundreds of meta:resourcekey="resource-key" with '<%$ Resources:[filename,]resource-key %>' in our web site too many web pages. I want to do it programmatically.
first of all I'm not able to open .aspx files using XmlDocument, then I wonder how can I read meta:resource entries inside the aspx file as meta:resource is not any regular node attribute. any thoughts or example code how to solve this.
Thx.
Note: in the inserted '<%$ Resources:[filename,]resource-key %>' filename name sould be based on the aspx file name & resource-key on the control type and the resource value.
exemple: in UserPage.aspx page <asp:Label id="uid" meta:resource="userName"> should be replaced with <asp:Label id="uid" Text='<%$ Resources:UserPage,LBL_userName_text %>'.
Html is not valid xml, so no wonder an XmlDocument didn't work. Especially with that <%$ .. %> syntax.
Why not read it as plain text and search for the string "meta:resourcekey"?
This isn't a programming answer, but a utility like PowerGREP may be a viable solution.

Is a HTML Table better than a Gridview in ASP.NET MVC?

I am looking into binding some data. What method of output would be better. I usually use Gridviews, but I am unsure if the table would be better now.
You should really steer clear of ASP.NET Web Forms controls when using the MVC framework. They don't play nicely together 100% of the time.
The HTML helpers/ standard HTML elements are the replacement. The idea being that you have more control over what you're doing that with Web Forms.
There are some nice grids available:
jqGrid (example of use with MVC here)
And the awesome MVCContrib project.
If all you're looking to do is present(output) a table of data, no need for a gridview at all (besides, in MVC, you most likely wouldn't want to anyway).
Simply loop through your model collection and create a new table row for each item:
<table>
<% foreach (var item in Model) { %>
<tr><td>FieldName</td><td><%= Html.Encode(item.Field) %></tr>
<% } %>
</table>
you can format up your table however you like by applying the appropriate css class to it.
EDIT: a better example to show multiple fields, also showing how to display no data.
<% if (Model.Count() > 0)
{ %>
<table width="35%">
<thead><tr><th>Species</th><th>Length</th></tr></thead>
<% foreach (var item in Model)
{ %>
<tr>
<td><%= item.FishSpecies%></td>
<td align="center"><%=item.Length%></td>
</tr>
<% } %>
</table>
<% }
else
{ %>
No fish collected.
<%} %>
That really depends on what you are outputting.
I only use tables / gridview for tabular data.
For other stuff i use Repeater controller or FormView.
While you can partially use ASP.NET server controls in MVC applications (e.g. a menu will render quite well), you should expect that they won't expose the expected or rich behavior you are used to see in ASP.NET. There's a number of reasons for that:
They typically rely on ViewState (and ControllerState)
You are required to put them inside a form tag with runat="server". Most controls check that this is the case indeed
Related to this, they rely heavily on the postback paradigm, which is not used in ASP.NET MVC
As a typical example of behavior that you won't find back, there is paging and sorting ...
When you delve into it, you soon find out that the helpers available in the MVC framework allow you to generate tabular data quite efficiently ....

ASP.NET C# language file doesn't work

I just started using explicit resource files. I performed these steps:
In the root create the folder: App_GlobalResources
Add two resx files: LocalizedText.en-us.resx and LocalizedText.resx
In both files I have a value called 'InstitutionTitle'
In LocalizedText.en-us.resx the value is 'Institution' and in the LocalizedText.resx the value is 'Instelling'
In my .aspx file I have the following label:
<asp:Label ID="lblInstitution" runat="server" Text="<%$ Resources:LocalizedText, InstitutionTitle %>" />
When I run this page, I always get the dutch version. Whether I set the language in my browser (FF and IE7) or not, I always get the dutch version. When I request the browsers' language I get en-us (using: Response.Write(Request.Headers["Accept-Language"]);).
What's the issue and how can I fix it?
Setting the language preferences in the browser is not enough. You have to make sure that the current thread's Culture and UICulture properties are set accordingly in ASP.NET.
You can do this either programmatically or declaratively on your page (Culture and UICulture attributes of the <%#Page %> directive).
Or you can let ASP.NET set them automatically by setting the web.config entry shown below and setting the Culture/UICulture properties of the page/masterpage to "auto".
// web.config:
<globalization enableClientBasedCulture="true" ...>
// page/masterpage:
<%# Page ... Culture="auto" UICulture="auto" %>
Check this page for details.
#martijn:
check the browsers caching settings.
Caching should be off all the time
when developing.
Install Firebug (FF) and Fiddler(IE)
to see what's being transfered over
the wire.
Hope this helps...
signed,
A fellow countryman

Categories