Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
DropDownlist不';不支持更改语言-ASP.NET-C#-区域性。参数名称:name_C#_Asp.net_Visual Studio 2015_Uiculture - Fatal编程技术网

DropDownlist不';不支持更改语言-ASP.NET-C#-区域性。参数名称:name

DropDownlist不';不支持更改语言-ASP.NET-C#-区域性。参数名称:name,c#,asp.net,visual-studio-2015,uiculture,C#,Asp.net,Visual Studio 2015,Uiculture,我正在尝试制作两个下拉列表。 一个用于更改主题,另一个用于更改UI区域性。 改变主题的方法效果很好,但是改变文化有一个问题 第一次运行时,我只能在InitializeCulture()函数中设置区域性,但在下拉列表中更改选择时,我无法重新设置区域性 这是我的解决方案: 这在Web.config中 <profile defaultProvider="MyProfileProvider"> <providers> <add name="MyProfile

我正在尝试制作两个下拉列表。 一个用于更改主题,另一个用于更改UI区域性。 改变主题的方法效果很好,但是改变文化有一个问题

第一次运行时,我只能在InitializeCulture()函数中设置区域性,但在下拉列表中更改选择时,我无法重新设置区域性

这是我的解决方案:

这在Web.config中

 <profile defaultProvider="MyProfileProvider">
  <providers>
    <add name="MyProfileProvider" connectionStringName="MyMembershipCon" applicationName="/" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
  </providers>
<properties>
  <add name="Language" type="string"/>
  <add name="Theme" type="string"/>
</properties>
</profile>
public partial class AdminPage : System.Web.UI.Page
    {
        string lang;
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                if(Session["Theme"]!=null)
                {
                    DropDownList1.SelectedValue = Session["Theme"].ToString();

                }

                if (Session["Language"] != null)
                {
                    DropDownList2.SelectedValue = Session["Language"].ToString();

                }
            }
        }



        protected void Page_PreInit(object sender, EventArgs e)
        {

            if(Session["Theme"]==null)
            {
                if(HttpContext.Current.Profile["Theme"].ToString()!="")
                {
                    Session["Theme"] = HttpContext.Current.Profile["Theme"];

                }
                else
                {
                    HttpContext.Current.Profile["Theme"] = "Theme1";
                    Session["Theme"] = "Theme1";
                    Page.Theme = "Theme1";
                }
            }

            if (Session["Language"] == null)
            {
                if (HttpContext.Current.Profile["Language"].ToString() != "")
                {
                    Session["Language"] = HttpContext.Current.Profile["Language"];

                }
                else
                {
                    HttpContext.Current.Profile["Language"] = "ar-EG";
                    Session["Language"] = "ar-EG";

                }
            }

            lang = Session["Language"].ToString();
            Page.Theme = Session["Theme"].ToString();
        }

        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            Session["Theme"] = DropDownList1.SelectedValue;
            HttpContext.Current.Profile["Theme"] = DropDownList1.SelectedValue;
            Response.Redirect(Request.Url.AbsolutePath);
        }

        protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
        {

            Session["Language"] = DropDownList2.SelectedValue;
           HttpContext.Current.Profile["Language"] = DropDownList2.SelectedValue;
            Response.Redirect(Request.Url.AbsolutePath);


        }
        protected override void InitializeCulture()
        {
            lang = "ar-EG";
            if (Session["Language"] != null)
            {

                lang = Session["Language"].ToString();
            }

            Page.UICulture = lang;
            Page.Culture = lang;

            base.InitializeCulture();
        }

    }