I can do the multilingual website in asp.net when language is similar ( dir=ltr for example English, Spanish, French). I would like to know how to do the same when one language dir=ltr (English) and other language dir=rtl (Arabic).
I would appreciate if some one can link to a resource which can show how to do this step by step as along with themes one for English and other for Arabic..
I am using ASP.Net 4.0 .
I would appreciate any help in this area and if someone can provide me with a two page example that would be great.
you can try like this ...
It is easy to develop multi language supported web site using ASP.NET . Just follw that step by step.
1.Take a new web site
2.Add “App_GlobalResources” from ASP.NET folders
3.Take a *.resx file (Strings.resx)
4.Enter Name and values
5.Make different *.resx file for different languages and name like that Strings.en-US.resx (for US english), Strings.fr-FR.resx (for
French). Make as many language file you needed
6.Now time for calling and using language from web page You website Solution Explorer will look like below image...
Default.aspx file will look like that
<asp:Label ID=”lblName” runat=”server” Text=”Label”></asp:Label>
<asp:Label ID=”lblDesc” runat=”server” Text=”Label”></asp:Label>
<asp:Label ID=”lblComments” runat=”server” Text=”Label”></asp:Label>
<asp:LinkButton ID=”lnkEnglish” runat=”server” OnClick=”lnkEnglish_Click”>English</asp:LinkButton>
<asp:LinkButton ID=”lnkFrench” runat=”server” OnClick=”lnkFrench_Click”>French</asp:LinkButton>
Codes of Default.aspx.cs
private ResourceManager rm;
protected void Page_Load(object sender, EventArgs e)
{
CultureInfo ci;
if (!IsPostBack)
{
Thread.CurrentThread.CurrentCulture = new CultureInfo(“en-US”);
rm = new ResourceManager(“Resources.Strings”, Assembly.Load(“App_GlobalResources”));
ci = Thread.CurrentThread.CurrentCulture;LoadData(ci);
}
else
{
rm = new ResourceManager(“Resources.Strings”,Assembly.Load(“App_GlobalResources”));
ci = Thread.CurrentThread.CurrentCulture;LoadData(ci);
}
}
protected void lnkEnglish_Click(object sender, EventArgs e)
{
Thread.CurrentThread.CurrentCulture = new CultureInfo(“en-US”);
LoadData(Thread.CurrentThread.CurrentCulture);
}
protected void lnkFrench_Click(object sender, EventArgs e)
{
Thread.CurrentThread.CurrentCulture = new CultureInfo(“fr-FR”);
LoadData(Thread.CurrentThread.CurrentCulture);
}
public void LoadData(CultureInfo ci)
{
lblName.Text = rm.GetString(“EventName”, ci);
lblDesc.Text = rm.GetString(“EventDescription”, ci);
lblComments.Text = rm.GetString(“EventComments”,ci);
}
Related
i have applied globalization on default page but it is not applied on Web User Control.
I have created Header.ascx and put two linkButton one for English and second for spanish.
i am using code on header.ascx form code is below ... .
this code for english
protected void lbtnEng_Click(object sender, EventArgs e)
{
HttpCookie cookie = new HttpCookie("CultureInfo");
cookie.Value = "en";
Response.Cookies.Add(cookie);
Thread.CurrentThread.CurrentCulture = new CultureInfo("en");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en");
Server.Transfer(Request.Path);
}
this code for Spanish language
protected void lbtnSpan_Click(object sender, EventArgs e)
{
HttpCookie cookie = new HttpCookie("CultureInfo");
cookie.Value = "es-mx";
Response.Cookies.Add(cookie);
Thread.CurrentThread.CurrentCulture = new CultureInfo("es-mx");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("es-mx");
Server.Transfer(Request.Path);
}
this code change language on default page label text but not on web user control label
declare control on default page
<asp:Label ID="lbl_test" runat="server" Text="<%$ Resources:Resource, Test %>"></asp:Label>
and on web control
<asp:Label ID="lbl_test" runat="server" Text="<%$ Resources:Resource, Test %>"></asp:Label>
you can set only one language at a time. In order to achieve your task .Use static strings or Take one resource file which consist of key value pairs. This is an example for submit key.
ResourceFileForStaticStrings.resx
Key Value
submitEnglish Submit
submitSpanish Presentar
Store it in a session or a cookie: Try the below one
System.Threading.Thread.CurrentThread.CurrentUICulture = New System.Globalization.CultureInfo(Session("es").ToString)
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture(Session("es").ToString)
Am using VS 2010 and created a sample web application. Added a dataset and report and created an SP which just return one row. No variables included as of now. Just simple SP w/o any parameters. In the web app, added an aspx page and in that page added a report viewer control.
My Aspx page goes as below:
<rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana"
Font-Size="8pt" InteractiveDeviceInfos="(Collection)"
WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt">
</rsweb:ReportViewer>
Code behind goes as below:
protected void Page_Load(object sender, EventArgs e)
{
ReportViewer1.Visible = true;
ReportDataSource dataSource = new ReportDataSource("DataSet1", LoadData().Tables[0]);
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(dataSource);
ReportViewer1.LocalReport.Refresh();
}
private DataSet LoadData()
{
var dataset = new DataSet();
using (var con = new SqlConnection(ConfigurationManager.ConnectionStrings["CString"].ConnectionString))
{
var command = new SqlCommand("[spSampleReport]")
{
Connection = con,
CommandType = CommandType.StoredProcedure
};
var adap = new SqlDataAdapter(command);
con.Open();
adap.Fill(dataset, "DataSet1");
}
return dataset;
}
In my web config, have added following in httphandlers section:
When Running, there is nothing shown on the page. Even the report viewer toolbars are not shown.
I am no ReportViewer expert but I think you need an .rdlc to tell the report viewer what to render.
ReportViewer.LocalReport.ReportPath = Server.MapPath(string.Format(#"~\Reports\Definitions\{0}.rdlc", reportName));
Make sure the DataSet name in the .rdlc is the same as the DataSource specified when you create you ReportDataSource
I found a good example to generate rdlc reports in asp.net with code example
http://www.dotnetsharepoint.com/2013/09/how-to-create-rdlc-reports-in-aspnet.html#.UjhvAsafh88
This question already has an answer here:
How can I pass values from one form to another in Asp.net
(1 answer)
Closed 7 years ago.
I have a site/portal created in ASP.net and VB.net.
I want to know how to reference variables between two asp pages, but not the pages themselves, I want to directly transfer data from the .aspx.vb bit of the page to another pages .aspx.vb file. Is that possible?
An easy way in asp.net/VB.net is to use session variables.
Session("myVariable") = "blah"
From another .aspx.vb page you can now use this value. Example:
Dim strTest as String = ""
strTest = Session("myVariable")
You can access this page on any of your .aspx pages for this session by referencing Session("myVariable")
if it's Not sensitive data you can do something like this,
Original page:
protected void Button1_Click(object sender, EventArgs e)
{
string MyOccupation = "Software Developer";
string url;
url = "page2.aspx?occupation=" + MyOccupation;
Response.Redirect(url);
}
Next Page:
string RetrievedValue;protected void Page_Load(object sender, EventArgs e)
{
this.TextBox1.Text = Request.QueryString["occupation"];
RetrievedValue = this.TextBox1.Text;
}
taken from http://forums.asp.net/t/1223291.aspx
Duplicate of How can I pass values from one form to another in Asp.net
Client side technology: Query String
Query String: For SEnding:
string name="abc"; Response.Redirect(" Page2.aspx?name= "+name);
For Getting: On Page2.aspx string name=Response.QueryString.GetValue(" name ");
Server Side Technology:Session
For Setting: Session["Name"] = "Abc";
For Getting: string str = Session["Name"].ToString();
In Session you can pass any object type.
Since nobody posted this, here is Microsoft's page about passing values between pages. It gives C# and VB examples: http://msdn.microsoft.com/en-us/library/6c3yckfw.aspx
on the server side, I've got these:
ASPX:
<form id="form1" runat="server" enctype="multipart/form-data">
<input type="file" id="myFile" name="myFile" />
<asp:Button runat="server" ID="btnUpload" OnClick="btnUploadClick" Text="Upload" />
</form>
CS:
protected void btnUploadClick(object sender, EventArgs e)
{
HttpPostedFile file = Request.Files["myFile"];
if (file != null && file.ContentLength > 0)
{
string fname = Path.GetFileName(file.FileName);
file.SaveAs(Server.MapPath(Path.Combine("~/Files/", fname)));
}
}
Client Side app: it uses WebClient but I didn't think this was needed for any solution since webclient is pretty simple and straight forward. Anyways, here's the code
private void btnStart_Click(object sender, RoutedEventArgs e)
{
Uri uploadAddress = new Uri("http://localhost/WebUpload/default.aspx");
WebClient wc = new WebClient();
wc.UploadProgressChanged += new UploadProgressChangedEventHandler(wc_UploadProgressChanged);
wc.UploadFileCompleted += new UploadFileCompletedEventHandler(wc_UploadFileCompleted);
wc.Credentials = CredentialCache.DefaultCredentials;
wc.UploadFile(uploadAddress, "POST", m_filename);
}
void wc_UploadFileCompleted(object sender, UploadFileCompletedEventArgs e)
{
if (e.Error != null)
txtProgress.Content = e.Error.Message;
else
txtProgress.Content = "Completed";
}
void wc_UploadProgressChanged(object sender, UploadProgressChangedEventArgs e)
{
txtProgress.Content = String.Format("{0}% completed",
e.ProgressPercentage);
}
as for the client app: it's a simple webclient using uploadfileasync via HTTP POST to the aspx page.
Question: files gets saved normally using the aspx page but for the client app, the file gets uploaded and but doesn't get saved on the folder. What might be happening? I'm pretty sure this is a server side problem.
Update: added the client side code. The client app works on another (but asp classic) server so I'm doubting that the client is the one that needs fixing.
Reposting my comment since Jan never posted an answer.
Thanks to Jan for pointing me to the right direction. The file receiving code should have been in the page_load, that was careless of me. Another problem was the string name of the index of the file (Request.Files["myFile"]) which should be of the same id as the input control in the aspx page.
So I have an asp:Login field on my login page.
However, I want to use a path for the create account url and the forgot password url. So I have to do it in Page_Load or maybe Page_Init. Regardless, neither option works, it simply refuses to modify the login form.
protected void Page_Load(object sender, EventArgs e)
{
string accountpath = Request.Url.AbsoluteUri + "/user/RequestAccount.aspx";
string forgotpath = Request.Url.AbsoluteUri + "/user/ForgotPassword.aspx";
lgnMain.CreateUserUrl = accountpath;
lgnMain.PasswordRecoveryUrl = forgotpath;
lgnMain.InstructionText = "test";
lgnMain.Focus();
}
protected void Page_Init(object sender, EventArgs e)
{
string accountpath = Request.Url.AbsoluteUri + "/user/RequestAccount.aspx";
string forgotpath = Request.Url.AbsoluteUri + "/user/ForgotPassword.aspx";
lgnMain.CreateUserUrl = accountpath;
lgnMain.UserName = "test";
lgnMain.InstructionText = "test";
lgnMain.PasswordRecoveryUrl = forgotpath;
}
The CreateUserUrl and the PasswordRecoveryUrl are ignored if you haven't set the CreateUserText and PasswordRecoveryText properties respectively. Since the Text properties probably don't need to be dynamic, just set them in the ASPX (although you could still set them in the code behind if required), and then the dynamic setting of the URL properties (in the Page_Load event) should work without problem.
Documentation here: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.login_members(v=vs.85).aspx
From the Documentation above:
If the CreateUserText property is
empty, the link to the registration
page is unavailable to the user.
If the PasswordRecoveryText property
is empty, the link to the password
recovery page is not available to the
user.
have you tried setting it in the markup?
<asp:Login id="lgnMain" runat="server"
CreateUserText="Register"
CreateUserUrl="~/user/RequestAccount.aspx"
PasswordRecoveryText = "Forgot Password"
PasswordRecoveryUrl = "~/user/ForgotPassword.aspx" >
</asp:Login>