Backend Viewstate
Hi,
I'm developing one backend custom module and i can't get Viewstate["key"] value after postback. In debug the this.Page.EnableViewstate is false. How can i enable it.
In frontend i put :
protected
override
void
OnInit(EventArgs e)
this
.Page.EnableViewState =
true
;
base
.OnInit(e);
Hello JV,
The PageElement which you should use to create backend pages has a property EnableViewState that you can set to true. The default value is false.
Regards,
Ivan Dimitrov
the Telerik team
Hi,
I am new at sitefinity and I'm developping a backend simple "hello World" user control (.ascx) with a asp button but when using the button after drag the control to the page a fall in this error:
Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request.
<
asp:LinkButton
ID
=
"BtAdd"
runat
=
"server"
onclick
=
"BtAdd_Click"
>add</
asp:LinkButton
>
Hi Paulo,
The problem is that you have clicked the button when you are working in edit mode. You can hide the button while working in edit mode by using this.IsDesignMode() extension or cancel all navigation or post backs.
We have logged a bug for this issue and hopefully it will be resolved for the RC release.
canceling the click
protected
void
Page_Load(
object
sender, EventArgs e)
if
(
this
.IsDesignMode())
this
.button.OnClientClick =
"return false;"
;
Ivan,
Hello Lorne,
In the RC you should use PageDataElement which has a public property EnableViewState. Inside InstallPages method in the custom module you can set the EnableViewState to true
sample
protected
override
void
InstallPages(SiteInitializer initializer)
var pageManager = initializer.PageManager;
var moduleNode = pageManager.GetPageNode(SiteInitializer.ModulesNodeId);
var id = ModulePageGroupId;
var myNode = pageManager.GetPageNodes().Where(t => t.Id == id).SingleOrDefault();
if
(myNode ==
null
)
myNode = initializer.CreatePageNode(ModulePageGroupId, moduleNode);
myNode.Name =
"test"
;
myNode.ShowInNavigation =
true
;
myNode.Attributes[
"ModuleName"
] = myModule.ModuleName;
Res.SetLstring(myNode.Title, ResourceClassId,
"PageGroupNodeTitle"
);
Res.SetLstring(myNode.UrlName, ResourceClassId,
"PageGroupNodeTitle"
);
Res.SetLstring(myNode.Description, ResourceClassId,
"PageGroupNodeDescription"
);
id =
this
.LandingPageId;
var landingPage =
pageManager
.GetPageNodes()
.SingleOrDefault(p => p.Id == id);
if
(landingPage ==
null
)
var pageInfo =
new
PageDataElement()
PageId =
this
.LandingPageId,
Name =
"myNode"
,
MenuName =
"myNodeTitle"
,
UrlName =
"myNodeUrlName"
,
Description =
"myNodeDescription"
,
HtmlTitle =
"myNodeHtmlTitle"
,
ResourceClassId = ResourceClassId,
IncludeScriptManager =
true
,
ShowInNavigation =
false
,
EnableViewState =
true
,
TemplateName = SiteInitializer.BackendTemplateName
;
....
......
Ivan,
Thanks for the code.
I don't see a method called InstallPages(...). I do see Install(...), which I used.
Your code is very incomplete. What do I do with the PageDataElement that is instantiated?
Here is a snippet of code I was using:
var sf = App.WorkWith();
...
sf.Page().CreateNewStandardPage(LandingPageId, SubPageId).Do(p =>
p.Page.EnableViewState = true;
p.Name = "MY NAME";
p.UrlName = "MY NAME";
p.Description = "";
p.ShowInNavigation = false;
p.Attributes["ModuleName"] = "MY MODULE";
)
...
p, however, is not a PageDataElement, but rather a PageNode.
In any case, the ViewState does not work for me.
Hello Lorne,
This is a sample code, it is not entire implementation and there is a mark "sample" before the code block.
About 2 moths ago we made a refarctoring inside SiteInitializer method and InstallPages method and
PageDataElement which represents configuration element for a page exists on 100 %. Most probably you are using an old version rather than RC2.
We are working on a sample project - module that will be shipped as a part of the SDK with the official release. The module will show you how to create backend pages, controls, custom types etc.
Best wishes,
Ivan Dimitrov
the Telerik team
Ivan,
Which class has the InstallPages(...) method?
Thanks.
Hello,
InstallPages is an abstract method of ContentModuleBase(Represents generic content module.)
There is a base class which has two methods related to the installation - one of then is abstracted
public abstract void Install(SiteInitializer initializer); and the other one is virtual
virtual void Initialize(ModuleSettings settings)
Best wishes,
Ivan Dimitrov
the Telerik team
Okay. I am subclassing from ModuleBase, which is why I did not see that method. (I assume I should continue subclassing ModuleBase if my module does not deal with "content".)
However, my problem remains: I still need a simple way of enabling ViewState on my admin page.
Hello,
I am not able to replicate an issue with the ViewState in the latest build. The view state mode could be tested with a simple code
var man = PageManager.GetManager();
var pnds = man.GetPageNodes().Where(p => p.Title ==
"MyBackendPage"
).ToList();
foreach
(var pn
in
pnds)
if
(pn.Page !=
null
&& pn.IsBackend)
pn.Page.EnableViewState =
true
;
man.SaveChanges();
I am getting a kinda the same problem. The only difference is that I'm working on a control with its own control designer template. I need to be able to save data to my viewstate during design mode. Was this issue resolved in SiteFinity 5? That's the version we're currently using.
I am getting a kinda the same problem. The only difference is that I'm working on a control with its own control designer template. I need to be able to save data to my viewstate during design mode. Was this issue resolved in SiteFinity 5? That's the version we're currently using.