SF 4.1 - Modules - ViewState, PostBacks and the .NET LifeCycle
One of the main new features mentioned as part of SiteFintiy 4.1 is the ability to use standard ASP.NET ViewState, PostBacks and the .NET LifeCycle to design the backend pages of modules.
Is there something that needs to be turned to activate this functionality?
I have created a new module using the Jobs module as a starting point. On the main backend landing page for my module I have a repeater that displays the items that have been saved, (not a RadGrid). In this repeater I have text boxes that the user can change, and there is a "Save" button at the bottom.
When I click the Save button, though, the repeater appears to have lost its viewstate because it doesn't have any items. I should be able to enumerate the Repeater Items, get a reference to the text box, and save the value that the user typed in..
How can I solve this problem in SiteFinity 4.1?
Thanks.
Hi Chris,
Make sure that you enabled the ViewState from the page properties section.
All the best,
Ivan Dimitrov
the Telerik team
I went into the "Administration -> Backend Pages" and clicked to edit the page that my module created during the Install step. I went into the "Advanced Options" section and checked "Enable Viewstate". When clicking save I was prompted to type in a name for the page, since the automatic creation of the page didn't give it a name. I gave the page name and clicked save. It saved successfully.
I restarted my application and went back into my module's admin page. Setting a breakpoint in my button click method shows that the repeater still doesn't retain any items after postback.
I also tried adding ViewStateMode="Enabled" on the ascx page for this interface. That didn't work either.
Hello Chris,
Please share the code you use to get/set the TextBox values and the way you are binding the repeater.
Kind regards,
Ivan Dimitrov
the Telerik team
Binding the repeater (this works):
protected
void
UpdateDisplay()
var module =
new
SlideshowModule();
Repeater SlideshowImageRepeater = GetControl<Repeater>(
"SlideshowImageRepeater"
);
SlideshowImageRepeater.DataSource = module.GetSlideshowItems();
SlideshowImageRepeater.DataBind();
protected
void
SlideshowImage_OnItemDataBound(
object
sender, RepeaterItemEventArgs e)
if
(e.Item.DataItem ==
null
)
return
;
Document doc = (Document)e.Item.DataItem;
Literal IDLiteral = e.Item.FindControl<Literal>(
"IDLiteral"
);
TextBox SortOrderTextBox = e.Item.FindControl<TextBox>(
"SortOrderTextBox"
);
IDLiteral.Text = doc.Id.ToString();
SortOrderTextBox.Text = doc.GetValue<
int
>(
"SortOrder"
).ToString();
void
UpdateSortOrder_Click(
object
sender, EventArgs e)
SlideshowModule module =
new
SlideshowModule();
Repeater SlideshowImageRepeater = GetControl<Repeater>(
"SlideshowImageRepeater"
);
foreach
(RepeaterItem item
in
SlideshowImageRepeater.Items)
Literal IDLiteral = item.FindControl<Literal>(
"IDLiteral"
);
TextBox SortOrderTextBox = item.FindControl<TextBox>(
"SortOrderTextBox"
);
module.UpdateSortOrder(
new
Guid(IDLiteral.Text), Convert.ToInt32(SortOrderTextBox.Text));
UpdateDisplay();
Any response?
Hi Chris,
Where you call UpdateDisplay()
? If you call this method inside PageLoad, CreateChildControls, InitializeControls and then you click a button there should not be a problem with the items collection, because all these methods will be executed before the Click of your button.
All the best,
Ivan Dimitrov
the Telerik team
When the button is clicked, I don't want "UpdateDisplay()" to be called until AFTER I save my data. Otherwise the repeater gets re-bound and I lose the values that the user typed into the textboxes.
The first time I called UpdateDisplay() is in the "InitializeControls()" method. But the code looks like this:
if (!Page.IsPostBack)
UpdateDisplay();
Hi Chris,
The only way that I am able to replicate this issue is when the EnableViewState property of the page is not set.
All the best,
Ivan Dimitrov
the Telerik team
The reason of this problem, is that one of the Validator controls does not have a value for the validation group property