I can't seem to find a detailed example of how a local resource file looks like and its content
I have been reading up on this link
http://msdn.microsoft.com/en-us/library/ms227427.aspx
I want to use implicit localization with local resources.
So if I have a page: Products.aspx and want to create a default resource file then I need to create Products.aspx.resx and placed in App_LocalResources folder?
What does it contain say for example I want to change the values for a button control with ID="btnSubmit" ?
Is it like:
btnSubmit.Text = "Click here" ?
Yes you would place the "Products.aspx.resx" in the App_LocalResources.
You would then create an item in the resource file where:
Name = btnSubmit.text
Value = Click Here
your aspx page would have the button with the resource key defined:
<asp:Button runat="server" ID="btnSubmit" meta:resourcekey="btnSubmit" />
Related
nesting of image inside a LinkButton shows image on one page & doesn't show image on another page below are two sample code from two different pages in the same root director.It works fine on one page but on the other page is doesn't show any download image rather shows the text download in place of image.
I have done troubleshooting for sometime and replace the code also but it doesnt show download image for any reason on the second page..
<asp:LinkButton ID="lnkbtnDownload" runat="server" onclick="lnkbtnDownload_Click" meta:resourcekey="lnkbtnDownloadResource1">
<asp:Image ID="imgDownload" runat="server" ImageUrl="~/images/download.png" meta:resourcekey="imgDownloadResource1" />
</asp:LinkButton>
<asp:LinkButton ID="lnkbtnDownload" runat="server" onclick="lnkbtnDownload_Click" meta:resourcekey="lnkbtnDownloadResource1">
<asp:Image ID="imgDownload" runat="server" ImageUrl="~/images/download.png" meta:resourcekey="imgDownloadResource1" />
</asp:LinkButton>
HTML OUTPUT
HTML for above two code sample render as below
<img alt="Download" src="images/download.png" id="MainContent_imgDownload">
Download
Both Pages are in the same root directory...
The problem probably comes from a discrepancy in your resource files or missing a resource file completely for the second page. Obviously you have one for the first, but possibly not for the other which has different naming.
If you are using meta:resourcekey, there are some things you have to considerate.
Make sure that your local resource files meet the following criteria:
They are in an App_LocalResources folder.
The base name matches the page name.
For example, if you are working with the page named Default.aspx, the
resource files are named Default.aspx.resx (for the default
resources), Default.aspx.es.resx, Default.aspx.es-mx.resx, and so on.
The resources in the file use the naming convention
resourcekey."property". For example, key name Button1."Text".
Source: MSDN
i have an asp.net webpage, which contains a label, now i want to get the text property of the label from the localresource file, i have a .resx file under App_LocalResources folder, which contains Name as UserNameLabel.Text and Value as User Name now in my aspx file i am using Label control like this
<asp:Label ID="UserNameLabel" runat="server" resourcekey="UserNameLabel"></asp:Label>
but i cannot get the text on the Label, can anyone tell me the correct way to add the Text Property from resource file
First you need to create appropriate structure inside web project. In this case I will be using Default.aspx:
Take notice I have placed Default.aspx.resx file inside App_LocalResources.
Next enter new item inside Default.aspx.resx like this:
The important thing is you need to set Text property (UserNameLabel.Text)
And finally here is aspx code:
<asp:Label ID="UserNameLabel" runat="server" meta:resourcekey="UserNameLabel"></asp:Label>
I have used meta:resourcekey to link to appropriate resource key.
I have a global resource file: ContactDetails.resx. In here are addresses and contact information used around the website.
I also have a contact page listing all the contact details, but changing depending on language. So on the UK website, the UK contact details appear at the top, whereas on the French website the French details will appear at the top.
Is there a way to nest resources, referencing a resource value from within the value of a different resource?
If a resource value doesn't exist in your French resource file, but does in your Default resource file, the system will automatically get the value from the default resource file.
So if your localization is set to fr, and your call is something like:
Resources.ContactDetails.Telephone
And Telephone doesn't exist in ContactDetails.fr.resx then it will get the Telephone value from ContactDetails.resx
If all the values are to be displayed on the page, but in a different order depending on the localization I would recommend not storing these in a resource file. The resource file variations are for changes in language, not to change layout of data.
Instead I would recommend to store these in the database, and have 3 literal controls on the page like:
<asp:literal id="ltl1stTelephone" runat="server" />
<asp:literal id="ltl2ndTelephone" runat="server" />
<asp:literal id="ltl3rdTelephone" runat="server" />
Then depending on the localization, specify which values should be assigned to each control.
if (System.Threading.Thread.CurrentThread.CurrentUICulture = "fr"){
.........
}
In my ASP.NET web form, I'm trying to customize my File Upload panel. What I do is simply put an HTML input button and a textbox. And there's a hidden HTML file upload control. When user clicks on the button, file select window appears, when user selects the file, the value is written to the visible textbox.
It's all good so far. But I'm having a problem while trying to attach the selected file to email in code page.
Here's the HTML markup:
<asp:ImageButton ID="clickme" runat="server" ImageUrl="Images/browse.png" OnClientClick="$('#uploadme').click(); return false;" />
<input id="uploadme" name="uploadme" type="file" style="visibility: hidden;" onchange="CopyMe(this, 'txtFileName');" />
<input id="txtFileName" type="text" name="txtFileName" readonly="readonly" class="file-path" />
And the JS (I use this in order to copy the file name only and write it into txtFileName just to show to user):
<script type="text/javascript">
function CopyMe(oFileInput, sTargetID) {
var arrTemp = oFileInput.value.split('\\');
document.getElementById(sTargetID).value = arrTemp[arrTemp.length - 1];
}
And the CSS:
input[type=file] { width: 1px; }
I'm using the below code in my .cs file to get the file attributes:
HttpPostedFile file = Request.Files["uploadme"]
But I kept on getting null value. So after some research, I've learnt that my form has to use enctype="multipart/form-data" property. Since my .aspx file is under a master page file, I added this property to the form in my master page file. Now Request.Files["uploadme"] is not null but its file name is empty string and its ContentLength is 0.
I'm unable to understand what might be the source to this issue. If it's because of using Master Page's form, I can't add a form to my child page because it says a page can have only 1 form. I don't know if I could use JavaScript for uploading because I need to email the file after uploading so I don't know how to get the file after I upload via JS.
How can I solve this problem? It could be one way or another, all I need is a stylized upload panel and to e-mail file after uploading.
You're using a master page and I'm presuming that you are using .net 2.0 or greater. If that's the case, use a FileUpload control (you can still hide it using CSS). Using the FileUpload control means you won't need the enctype attribute (although you shouldn't generate any problems having it there).
This all being said, I don't believe to you copy values into file type fields and have documents upload. This would be a MAJOR security flaw as a website could potentially upload files from your machine without your knowledge.
I have created a ProductResources.resx file. The name and value fields contain the ® character. THis is the R with a circle around it. It is a reg trademark. Obviously this needs to be there. An the resource file itself gives a red circle with a question mark inside it. Please help.
Depending on the encoding you declare for the resx XML, you can probably use one of the following:
® (iso-8859-1 or utf-8)
™ (unicode)
here's what you must do:
add a app_local_resources folder(right click on your project --> add asp.net folder)
name the resource folder as the following: PageName.aspx.resx
add the button name and property ( eg. Button1.Text) in the resource file name field
copy (by just highlight the registered trade mark from any source and copy it, paste in the value field from here
go to your button and add the following such as:
asp:Button ID="Button1" runat="server" Text="" onclick="Button1_Click" meta:resourcekey="Button1"
alt text http://img7.imageshack.us/img7/2108/59469768.jpg
hope this is what you want :)