文化变革和验证者

时间:2013-02-13 11:40:38

标签: c# asp.net validation culture


我正在为我的网站写一些表格,我遇到了以这种形式更改语言和验证器的问题。

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="site.aspx.cs" Inherits="site" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>test</title>
</head>
<body>
<form id="form1" runat="server">
       <div>

        <div  style="position:absolute; top:0; right:0;">
        <asp:LinkButton   id="linkButton1"
                  runat="server"
                  OnCommand="LinkButton1_Click"
                  CommandArgument="en-US">ENG
        </asp:LinkButton>

        </div>



        <asp:Table ID="table1" runat="server"  Width="700" >    


            <asp:TableRow>
                <asp:TableCell >
                    <asp:Label ID="Label2" runat="server" Text="<%$ Resources:Resource, name %>" ></asp:Label>
                </asp:TableCell>
                <asp:TableCell>
                    <asp:TextBox ID="model" runat="server"></asp:TextBox><br />
                        <asp:RequiredFieldValidator 
                            id="RequiredFieldValidator3" runat="server" 
                            ErrorMessage="<%$ Resources:Resource, required %>" 
                            ControlToValidate="name">
                        </asp:RequiredFieldValidator>
                </asp:TableCell>
            </asp:TableRow>


如您所见,有Name标签,我使用验证器。它只显示了1个fiels,我得到了很多。

这是我的cs。用于将文化从默认更改为英语的文件代码:

protected void LinkButton1_Click(object sender, EventArgs e)
    {
        Session["CurrentUI"] = "en-US";
        Response.Redirect(Request.Url.OriginalString);

    }

    protected override void InitializeCulture()
    {
        if (Session["CurrentUI"] != null)
        {
            String selectedLanguage = (string)Session["CurrentUI"];
            UICulture = selectedLanguage;
            Culture = selectedLanguage;

            Thread.CurrentThread.CurrentCulture =
                CultureInfo.CreateSpecificCulture(selectedLanguage);
            Thread.CurrentThread.CurrentUICulture = new
                CultureInfo(selectedLanguage);
        }

        base.InitializeCulture();
    }


该文件也有提交按钮代码。

问题是,当我尝试更改语言时,点击ENG LinkBut​​ton,所有带验证器的字段都不允许我更改..
只是测试我试图填写所有必填字段,然后它工作,我的文化改变了。问题可以在哪里?

0 个答案:

没有答案