Using postbackurls and viewstate in c# user control
Hi,
I have created a user control with 2 panels: the first panel has a form with a 'next' button that toggles the visibility of the panels; only one panel is visible at a time. On the second panel, I have a form with 3 buttons: Save, Add New and Delete.
Basically, the user can enter and save details of mulitple items, e.g. title and description. I am using ViewState to store the list of items.
When the user hits the Save button, it dynamically creates an Edit link for the item and displays the Edit link with the title in a list below the form and clears the form.
Edit Description of my first item Edit Description of my second item Edit Description of my third item
When the user hits the Edit link it loads the title and description back into the form, allowing the user to Delete or Edit the details and Save.
I set postbackurls for the Save and Delete buttons to ""/umbraco/page_name.aspx?" to remove the querystrings on postback.
Now.. I have created and tested this user control with c# in Visual Studio and it works perfectly. When I created a macro from this user control and inserted it into a page, the postbackurls and viewstate don't work :(
Getting past the first panel is OK; panelOne is hidden and panelTwo is visible. If I enter an item and description, then hit Save, postback appears to reload the page as though for the first time. The eventhandler for the buttons aren't firing (I put in debug statements).
I am hoping someone can shed some light because I'm stumped! Hopefully I've given enough information about what I've done and what I'm trying to achieve...I am running Umbraco 4.5.2, IIS 7 and Windows 7.
Are you actually redirecting to separate pages each time? ViewState isn't cross-page so what you write into one pages ViewState shouldn't be accessible on the next.
Also, you might be better off looking at the MultiView control, it has good handling for doing paged UIs.
No, all my controls are on the one page and I am using postbackurls to post back to itself.
I removed the postbackurls on the buttons and have checked the value of IsPostBack when the page is reloaded. The first time I click Save, IsPostBack = true but if I try to save another item or click the Edit link, IsPostBack = false.
Is this a ViewState issue? I don't understand why it works when I test the usercontrol in an aspx page in VisualStudio but not with Umbraco?
Using postbackurls and viewstate in c# user control
Hi,
I have created a user control with 2 panels: the first panel has a form with a 'next' button that toggles the visibility of the panels; only one panel is visible at a time. On the second panel, I have a form with 3 buttons: Save, Add New and Delete.
Basically, the user can enter and save details of mulitple items, e.g. title and description. I am using ViewState to store the list of items.
Item myItem = new Item(itemId, txtTitle.Text, txtDesc.Text);
List<Item> items = (List<Item>)ViewState["Items"];
items.Add(myItem);
ViewState["Items"] = items;
When the user hits the Save button, it dynamically creates an Edit link for the item and displays the Edit link with the title in a list below the form and clears the form.
E.g:
link_edit = new LinkButton();
link_edit.Text = "Edit";
link_edit.PostBackUrl = "/umbraco/page_name.aspx?id=" + itemId;
Expected output:
Edit Description of my first item
Edit Description of my second item
Edit Description of my third item
When the user hits the Edit link it loads the title and description back into the form, allowing the user to Delete or Edit the details and Save.
I set postbackurls for the Save and Delete buttons to ""/umbraco/page_name.aspx?" to remove the querystrings on postback.
Now.. I have created and tested this user control with c# in Visual Studio and it works perfectly. When I created a macro from this user control and inserted it into a page, the postbackurls and viewstate don't work :(
Getting past the first panel is OK; panelOne is hidden and panelTwo is visible. If I enter an item and description, then hit Save, postback appears to reload the page as though for the first time. The eventhandler for the buttons aren't firing (I put in debug statements).
I am hoping someone can shed some light because I'm stumped! Hopefully I've given enough information about what I've done and what I'm trying to achieve...I am running Umbraco 4.5.2, IIS 7 and Windows 7.
Thanks in advance
Are you actually redirecting to separate pages each time? ViewState isn't cross-page so what you write into one pages ViewState shouldn't be accessible on the next.
Also, you might be better off looking at the MultiView control, it has good handling for doing paged UIs.
No, all my controls are on the one page and I am using postbackurls to post back to itself.
I removed the postbackurls on the buttons and have checked the value of IsPostBack when the page is reloaded. The first time I click Save, IsPostBack = true but if I try to save another item or click the Edit link, IsPostBack = false.
Is this a ViewState issue? I don't understand why it works when I test the usercontrol in an aspx page in VisualStudio but not with Umbraco?
Hello Claire.
I'm having the same issue. did you find a solution?
- Lars Skjoldby, www.skjoldby.com
Hi there,
My workaround was to get the name control that caused the postback and then calling an event depending on which control caused the postback.
For example:
if (Page.IsPostBack)
{
Control c = GetPostBackControl(this.Page);
if (c != null)
{
if (c.ID == "btnSave") saveItem();
}
}
For link buttons, use
string ctrlname = this.Page.Request.Params.Get("__EVENTTARGET");
Hope this helps!
is working on a reply...