我注意到當我重新啓動我的機器時,我開發的webpart的定製屬性返回到它們的默認值。Sharepoint Webpart定製屬性獲取服務器重啓時的默認值
這是正常行爲嗎?是服務器啓動時保存的屬性,還是有一些我缺少的參數。
謝謝。
編輯:代碼:
namespace TestWebpart
{
[ToolboxItemAttribute(false)]
[XmlRoot(Namespace = "TestWebpart")]
public class GraphWebpart : Microsoft.SharePoint.WebPartPages.WebPart
{
// Visual Studio might automatically update this path when you change the Visual Web Part project item.
private const string _ascxPath = @"~/_CONTROLTEMPLATES/Test_Graph/TestWebpart/GraphWebpartUserControl.ascx";
protected override void CreateChildControls()
{
ReloadElements();
}
protected void ReloadElements()
{
Controls.Clear();
GraphWebpartUserControl control = (GraphWebpartUserControl)Page.LoadControl(_ascxPath);
control.xmlDataUrl = XMLFileUrl;
Controls.Add(control);
}
private static string _xmlFileUrl;
[WebBrowsable(true),
Personalizable(PersonalizationScope.Shared),
DefaultValue(""),
Description("xml"),
DisplayName("xml"),
WebDisplayName("xml")]
public string XMLFileUrl
{
get { return _xmlFileUrl; }
set {
_xmlFileUrl = value;
ReloadElements();
}
}
}
}
EDIT2: 刪除靜態從田間地頭引發流動異常:
Web Part Error: An error occurred while setting the value of this property: TestWebpart:XMLFileUrl - Exception has been thrown by the target of an invocation.
Hide Error Details
[WebPartPageUserException: An error occurred while setting the value of this property: Blue_Graph.GraphWebpart.GraphWebpart:XMLFileUrl - Exception has been thrown by the target of an invocation.]
at Microsoft.SharePoint.WebPartPages.BinaryWebPartDeserializer.ApplyPropertyState(Control control)
at Microsoft.SharePoint.WebPartPages.BinaryWebPartDeserializer.Deserialize()
at Microsoft.SharePoint.WebPartPages.SPWebPartManager.CreateWebPartsFromRowSetData(Boolean onlyInitializeClosedWebParts)
這是不作爲的性質在持久化到數據庫正常行爲。一些示例代碼總是有幫助... – 2010-09-13 01:36:32
好吧,我的代碼沒有什麼特別之處,請參閱更新。 – 0xFF 2010-09-13 08:14:19
跳到我身上的一件事就是你繼承的類。看看這裏的評論 - http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.webpartpages.webpart.aspx – 2010-09-13 11:03:48