Saving/editing parent and child information on same webpage - asp.net

This is a question related to how people are handling a situation in the user interface for a web application. I have a page which is displayed when a user wants to create/edit a Parent object. It has a few attributes related to this Parent object, as well as a Save button so the Parent can be saved. Each Parent object has a collection of Child objects (displayed in a grid on the same page), and on this same screen the user can add/modify/remove Child objects, similar to the following:
Parent Information:
ParentName: [textbox]
ParentDate: [datepicker]
Children Information:
ChildName ChildDate Delete
[textbox] [datepicker] [button]
[textbox] [datepicker] [button]
[textbox] [datepicker] [button]
[Add Child button]
[Save button] [Cancel button]
Notice that I really want to only have buttons when I need to: one Save button (to rule them all!). I am trying to enable the following scenario when the user is creating or editing a Parent object:
The user modifies Parent information (nothing saved to database yet)
The user adds/modifies/removes Child objects (nothing saved to database yet)
The user clicks Save (and all Parent and Child information is saved)
Through all kinds of fancy AJAX-ish stuff I can make this happen without page refreshes, but I am saving all the intermediate changes to the into the user's session on the web server each time in the meantime. For example: the user clicks "Add" button (to add a new Child object), so I go into the session, retrieve the Parent object I already had put there and add a new Child to the collection of Child objects, then bind this to the datalist. The next time the "Add" button is clicked, I have to save off the changes the user made to the first Child entry back into the object I retrieved from the session and repeat the process.
Is this crazy? Maybe I am trying to force "state" onto a "stateless" web application and shouldn't be doing that. I understand the concept of having per-lineitem editing in a grid, but that just seems silly for small screens where there's a couple of pieces of info for the Parent, a couple for each Child, and it's a lot of extra clicking for the user.
I think this question is technology independent, but just in case you need to know this is an ASP.NET web app.

I've done this sort of dynamic form generation work before also, and I tend to not save any of the user's input to the session. Sure, I'll query the server to ask about an object, but I won't expect the server to save any state information until I'm ready to post the form.
I don't think you're crazy, you're using a dynamic form and that's OK!

Related

FullCalendar: is there still a viewRender event hook?

I need something like the viewRender event in order to persist the user's state. I'm building a UI where users will frequently jump in and out of the calendar, so preserving their view/range is essential for a pleasant experience. Does this exist in v5? The last mention I can find of it is from v3.
The only workaround I can think of right now is a direct click handler on every view control element, or a very heavy-handed MutationObserver. This is a React app so either one is going to be super awkward.
Thank you!
Edit 2021-02-11:
I looked at the available view render hooks but none of them address my problem. What I need is an event that will fire whenever the view state changes, including clicking between weeks/months/etc., so that I can persist the date range the user most recently viewed as well as the view they had selected.
viewDidMount is the closest to what I need, but it does not fire when the date range changes.
Edit 2021-05-26:
Another problem with using viewDidMount is that using it to enact side-effects is a bit overeager. The hook gets called whether or not the user has actually done anything, and the default view always gets passed as view inside the View Object. So there's no way to tell whether this mount event contains data I should persist or not.

Need example of a web form editing a parent entity object with children

I'm working on an "edit" page for an object. On this page, I would like to have something like a DetailsView allowing editing of properties of the object as well as a GridView with children and allowing for simple Add/Edit/Delete of the children. The updates to the parent or child objects shouldn't save to the database until a Save button is clicked. I'm asp.net web forms and Entity Framework
As a simple example, imagine a Project object with a collection of Resources. I am building a page that allows a user to change Project properties such as ProjectName in a DetailsView as well as add/edit/deleting a Resource in a Gridview below. One Save button at the bottom saves everything.
I've found examples of this in MVC, but am having trouble finding a web forms example.
I am not able to code your application for you but I have accomplished this using one of two variants of the same pattern.
Create a record object for your children that is serializable and maintain that in a ViewState based List. If the data is significantly large, consider maintaining it in Session and use a unique key to your Session object (such as a GUID assigned at Page_Load) and stored the key in ViewState.
When your use is done editing the parent / children, you will have to resolve the changed to your ViewState / Session based objects to those stored on disk.

Exit button, without saving to database when items have already been added

I do not have any code to show, but using asp.net, vb.net, and SQL with stored procedures.
If on a page I have an item that is added to the database and therefore that information is "saved", is there a way to have an ("exit without saving") button on the page that does away with those changes?
Using infragisitcs ultrawebgrid, you add an item to one table. You can add an item to another table on that page. i assume adding these items to the table automatically saves in the database. There is also a text box but without clicking save I do not believe that those items are actually added to the database. Update panel is used, I don't know if that matters.
If after someone adds to the table but then decides.. oh wait.. I don't want to do this just yet, is there a "one-click" way to act as if I never visited that page to add info? I'm assuming it would be deleting the entries but this would have to be limited to deleting ONLY those items added while making... we don't want people adding info, then going back and deleting once the "save" button has been pushed.
There are a couple of options for handling 'undo,' you can handle it after they save by using markers in your database, or you can cache changes until they hit a 'commit' button that then saves their changes in the database.
Caching changes is the cheaper implementation, but then you can get caught with users who haven't figured out that they're not really saving anything until they take that final step.

best way to generate and highlight menu items on server (asp.net)

I have an ascx component, that holds two-level menu, because there are several user types, and the menu needs to be computed on server.
Anyways - I'm also doing the highlighting of current menu item on server (adding a selected class/css to an item). Highlighting with javascript is not good option, because there is content in datagrids, that causes postback and needs to remain the menu in the same position as selected value is.
So I am doing this as some kind of mapping with a hashtable (e.g. pairs (url-of-the-site, menu-item-to-highlight)), and i have to include a mapping for every site my web application contains in order i want to have menus highlighted... so somehow it bothers me that there has to be a better way to do this. are there any better techniques?
A technique I use on my master page/content pages with .NET 2.0 is to have a publicly accessible method called "SetNavigation" that takes a string character that correlates to the hyperlink control I want to highlight. What the method does is set the CSS stylesheet of the specified hyperlink to my "selected" one.
Then in my child pages, in the Page_Load method, I call the SetNavigation method and pass in the link based on the current page I'm on, such as SetNavigation("hypSearch")
I would gather that you could create a similar control on your ASCX control and then have your Page_Load events, or even button click events call the method if so desired.

How do I - in ASP.NET save the info from a page when a user leaves the page?

In our CMS, we have a place in which we enable users to play around with their site hierarchy - move pages around, add and remove pages, etc.
We use drag & drop to implement moving pages around.
Each move has to saved in th DB, and exported to many HTML files. If we do that in every move, it will slow down the users. Therefore we thought that it's preferable to let the users play around as much as they want, saving each change to the DB, but only when they leave the page - to export their changes to the HTML files.
We thought of making the user click a "publish" button when they're ready to commit their changes, but we're afraid users won't remember to do that, because from their stand point once they've moved a page to a new place - the action is done. Another problem with the button is that it's inconsistent with the behavior of the other parts of the site (for example, when a user moves a text inside a page, the changes are saved automatically, as there is only 1 HTML file to update)
So how can we automatically save user changes on leaving the page?
You should warn the user when he leaves the page with javascript.
From http://www.siafoo.net/article/67:
Modern browsers have an event called window.beforeunload that is fired right when any event occurs that would cause the page to unload. This includes clicking on a link, submitting a form, or closing the tab or window.
Visit this page for a sample the works in most browsers:
http://www.webreference.com/dhtml/diner/beforeunload/bunload4.html
I think it's bad practice to save the page without asking the user first, thats not how normal web pages work.
Sample:
<SCRIPT LANGUAGE="JavaScript1.2" TYPE="text/javascript">
<!--
function unloadMess(){
mess = "Wait! You haven't finished."
return mess;
}
function setBunload(on){
window.onbeforeunload = (on) ? unloadMess : null;
}
setBunload(true);
//-->
</SCRIPT>
The easiest way I can think of is to store the page info each time the user moves items around using Ajax (e.g. with an UpdatePanel, onUpdated event, let it fire some script that updates the users page config.
Alternatively - .Net's WebParts implementation does this automatically without intervention by the programmer (unless you want to change the storage engine, it uses a local mdb in by default.
Use a "Publish" checkbox/button and when the user interacts with the page in a way that causes them to navigate away ask them if they want to publish if that box is NOT checked/button not clicked. Be aware that there are actions (closing the browser, accessing their favorites menu, etc.) that you will probably not want or not be able to prompt the user.
I would force them to click a button such as publish. That is a 'training' issue.
Automatically saving changes when they leave could have other ramifications. For example if a user opens up a record and plays around with it and has no intention of changing it, they close it, like a word document, excel, etc. . . I would have your site mimic that model.
You also have to remember that the web is a disconnected environment and is not required all web applications run like a windows application.
If the user doesn't click the publish/save button then there changes are not saved and that is up to them to remember to do.

Resources