2012-07-14 49 views
0

這感覺就像一個基本問題,但我還是新手。如何重新加載ASP.NET用戶配置文件數據

我將ASP.NET TextBox控件值(例如用戶名,bio等)傳遞給我的代碼隱藏中的頁面方法,然後將這些值保存到用戶的配置文件中。這一切似乎工作正常。

[WebMethod] 
public static void UpdateProfile(Person formValues) 
{ 
    HttpContext.Current.Profile.SetPropertyValue("Bio", formValues.Bio); 
} 

(注 - formValues正在從一個AJAX後通過jQuery的提供)。

我希望看到實際反映在ASPX Web表單上的更新的配置文件信息,而無需手動刷新頁面以獲取最近更新的配置文件信息。這可能嗎?

下面是我在Page_Load方法

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

    } 
} 

我希望這是有意義的是做。 謝謝。

+1

確實有意義 - 例如,如果您的實際顯示位於另一個UpdatePanel中,則可以強制UpdatePanel刷新,使其重新加載用戶配置文件數據。其他策略可能包括通過JavaScript直接更新頁面上的文本。爲了幫助確定,瞭解您的配置文件顯示是否在UpdatePanel中進行託管會很有用。 – dash 2012-07-14 22:25:38

+0

@dash謝謝你的回覆。是的,當前的配置文件顯示在UpdatePanel中,我試圖讓它刷新。我也考慮過通過JavaScript更新控件,但是我將繼續觀察UpdatePanel方法是否能夠提供我想要的內容。乾杯。 – mulkraj 2012-07-15 10:20:49

回答

0

按照破折號的建議和做進一步閱讀,我實現了一個看起來像一個簡單的方法:添加一個隱藏的按鈕到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 --> 

..the的jQuery:

$("#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(); 

    }; 

這裏是相應的o對於隱藏按鈕n單擊事件處理程序:

protected void btnUserProfileUpdatePanel1_Click(object sender, EventArgs e) 
    { 
     UpdatePanel1.Update(); 
     ((Label)(lblProfileUserName)).Text = Profile.FirstName + " " + Profile.LastName; 
    } 

這可能不是最巧妙的方法,但它的工作,我學到了很多沿途。您的想法和意見非常感謝。

謝謝。

相關問題