Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/257.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
C# 如何重新加载ASP.NET用户配置文件数据_C#_Asp.net_Profile - Fatal编程技术网

C# 如何重新加载ASP.NET用户配置文件数据

C# 如何重新加载ASP.NET用户配置文件数据,c#,asp.net,profile,C#,Asp.net,Profile,这感觉像是一个基本问题,但我还是新手 我正在将ASP.NET文本框控件值(例如用户名、bio等)传递给代码隐藏中的页面方法,然后将这些值保存到用户的配置文件中。这一切似乎都运作良好 [WebMethod] public static void UpdateProfile(Person formValues) { HttpContext.Current.Profile.SetPropertyValue("Bio", formValues.Bio); } (注意-formValues是通过

这感觉像是一个基本问题,但我还是新手

我正在将ASP.NET文本框控件值(例如用户名、bio等)传递给代码隐藏中的页面方法,然后将这些值保存到用户的配置文件中。这一切似乎都运作良好

[WebMethod]
public static void UpdateProfile(Person formValues)
{
    HttpContext.Current.Profile.SetPropertyValue("Bio", formValues.Bio);
}
(注意-formValues是通过jQuery从AJAX Post提供的)

我希望看到更新的配置文件信息实际反映在ASPX web表单上,而不必手动刷新页面以获取最近更新的配置文件信息。这可能吗

下面是我在页面加载方法中所做的

protected void Page_Load(object sender, EventArgs e)
{
    if(!Page.IsPostBack)
    {
        FirstName.Text = Profile.FirstName;
        Bio.Text = Profile.Bio;

    }
} 
我希望这是有意义的。
谢谢。

按照dash的建议,并做了一些进一步的阅读,我实现了一种看似简单的方法:向
UpdatePanel
添加隐藏按钮,然后调用jQuery中隐藏按钮的onclick

(我提到过更新的概要信息是通过jQuery UI对话框收集的吗?)

以下是相关的ASPX代码:

    <!-- Change User Profile info -->
    <div id="profileBasicInfoDiv">
        <asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="True" UpdateMode="Conditional" Visible="True">
             <ContentTemplate>       
                 <asp:Label ID="lblProfileUserName" runat="server" Text="Name"></asp:Label>
                 <asp:Button ID="btnUserProfileUpdatePanel1" runat="server" Text="Button" Visible="True" onclick="btnUserProfileUpdatePanel1_Click" />        
            </ContentTemplate>     
       </asp:UpdatePanel>
       <br /> 
       <a href="#" id="hlShowBasicInfo">Change my details</a>
   </div> <!-- End of profileBasicInfoDiv -->
 $("#profileChangeBasicInfo").dialog({
            modal: true,
            buttons: { 'Save': function () { $(this).dialog('close'); }                    
            },
            close: function () { UpdateProfile(); }

        });
 function UpdateProfile() {

        var jsonText = "{'Bio':'" + $("[id$='MainContent_Bio']").val() + "','FirstName':'" + $("[id$='MainContent_FirstName']").val() + "'} ";
        sendData(jsonText);
        $("#MainContent_btnUserProfileUpdatePanel1").click();

    }; 
  protected void btnUserProfileUpdatePanel1_Click(object sender, EventArgs e)
   {
        UpdatePanel1.Update();
        ((Label)(lblProfileUserName)).Text = Profile.FirstName + " " + Profile.LastName;
   }
下面是隐藏按钮对应的onclick事件处理程序:

    <!-- Change User Profile info -->
    <div id="profileBasicInfoDiv">
        <asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="True" UpdateMode="Conditional" Visible="True">
             <ContentTemplate>       
                 <asp:Label ID="lblProfileUserName" runat="server" Text="Name"></asp:Label>
                 <asp:Button ID="btnUserProfileUpdatePanel1" runat="server" Text="Button" Visible="True" onclick="btnUserProfileUpdatePanel1_Click" />        
            </ContentTemplate>     
       </asp:UpdatePanel>
       <br /> 
       <a href="#" id="hlShowBasicInfo">Change my details</a>
   </div> <!-- End of profileBasicInfoDiv -->
 $("#profileChangeBasicInfo").dialog({
            modal: true,
            buttons: { 'Save': function () { $(this).dialog('close'); }                    
            },
            close: function () { UpdateProfile(); }

        });
 function UpdateProfile() {

        var jsonText = "{'Bio':'" + $("[id$='MainContent_Bio']").val() + "','FirstName':'" + $("[id$='MainContent_FirstName']").val() + "'} ";
        sendData(jsonText);
        $("#MainContent_btnUserProfileUpdatePanel1").click();

    }; 
  protected void btnUserProfileUpdatePanel1_Click(object sender, EventArgs e)
   {
        UpdatePanel1.Update();
        ((Label)(lblProfileUserName)).Text = Profile.FirstName + " " + Profile.LastName;
   }
这可能不是最优雅的方法,但它很有效,我在这一过程中学到了很多。非常感谢您的想法和评论


谢谢。

这很有意义-例如,如果您的实际显示在另一个UpdatePanel中,则可以强制该UpdatePanel刷新,从而使其重新加载用户配置文件数据。其他策略可能包括通过JavaScript直接更新页面上的文本。若要提供明确帮助,请了解您的配置文件显示是否位于UpdatePanel中。@dash感谢您的回复。是的,当前配置文件显示在UpdatePanel中,我正在尝试刷新它。我也考虑过通过JavaScript更新控件,但我会继续看看UpdatePanel方法是否能满足我的需求。干杯