Implementation of ModWatch

Mar 7, 2008 at 2:59 AM
This extender looks very promising for a project I am currently developing.

However I have some queries on the scope of the implementation.

I understand that you can attach an alert message to a button that will display the alert message if the watched controls have changed, but can this be extended to a button or more importantly a TreeView (node) control or menu control on a MasterPage, so that if a user wants to navigate to another page without saving the current data they receive the alert message.

In addition, when the user responds to the alert message how can the response be handle on the server-side, or is this not possible. Perhaps an example of handling the 'OK' response and the 'Cancel' response would answer my question.

Look forward to being able to implement this extender.
Coordinator
Mar 8, 2008 at 12:52 AM
Edited Mar 8, 2008 at 12:53 AM
Thanks for the feedback!!! Hope this is helpful:


can this be extended to a button or more importantly a TreeView (node) control or menu control
The TreeView and Menu controls do not provide access to client-side click events, so they are not as straight forward to handle. It may be possible to create custom TreeNode and MenuItem classes that provide this type of functionality, and I will look into a little more thoroughly.

However, there may be another option. I have released a new version (1.0.0.1) that contains a small change to make this easier.
Because the TreeView and Menu controls do not expose client-side events, you will have to alter the NavigateUrl of the TreeNode/MenuItem to check for any modifications that may have been made to the page. I have added a sample page demonstrating use of the ModWatch extenders with the TreeView and Menu controls (see TreeViewTest.aspx). This page utilizes the client-side ModManager to determine if a change has occurred before allowing the user to redirect.


when the user responds to the alert message how can the response be handle on the server-side
The ModWatch controls do not currently provide these type of server-side events. This may be a feature that is easily added, however, I'm not completely sure what is desired. The current OnClickModAlertExtender control will prompt the user if a change has been made, if the user clicks 'Cancel', then a postback will not occur, and no server-side event would be able to fire. I do see the desire for an event that fires when the user clicks the 'OK' button... I will work on this addition.
Mar 10, 2008 at 4:29 AM
Thanks for the enhancements, I can see where you are going. However for the specific project I am working on the TreeView is databound to an SQLDataSource with custom bindings that set the ValueField to the URL, so that I can intercept the SelectedNodeChanged event to save the TreeView state and redirect to the selected URL. I was hoping to be able to query the ModManager in this procedure for changes and display a MsgBox if changes existed (like in your client-side java script), but the property doesn't exist on the server-side. Is this a possible enhancement?

Thanks again for your effort.
Coordinator
Mar 12, 2008 at 1:28 AM
I've released another version that contains two overloads of an IsDirty method on the server side ModManager class. Hopefully this will give you what you are looking for.
Mar 13, 2008 at 2:10 AM
Thanks again for the enhancements, that is what I need.

I am starting to implement ModWatcher on some databound pages and have come across another limitation. I use a dropdownlist to move to the nth record of a datasource, so an OnSelectedIndexChangedModAlertExtender for a dropdownlist would be useful. I would try myself, but I am not a C# coder and the extender framework is still a bit foriegn to me.

Another issue which I am trying to resolve relates to my previous post. The content page (within a master page) implements IModWatcherContainer and I can use IsDirty to know whether a save to the DB is required. However, if a nodechange occurs on the treeview of the masterpage I am not sure how to reference the content page's ModManager.IsDirty property.

Any assistance would be appreciated, as I realise this is moving off the topic.
Coordinator
Mar 17, 2008 at 12:54 AM

I use a dropdownlist to move to the nth record of a datasource, so an OnSelectedIndexChangedModAlertExtender for a dropdownlist would be useful.

A group of controls has been added to alert the user of changes on events such as SelectedIndexChanged. The added controls are: ModAlertDropDownList, ModAlertListBox, ModAlertCheckBox, ModAlertCheckBoxList, ModAlertRadioButton, ModAlertRadioButtonList.

Each control inherits from it's asp server control counterpart, so you can use ModAlertDropDownList just as you would a DropDownList. Just provide values for the NotifyModMessage and ModGroup properties, and it will provide the desired functionality.



However, if a nodechange occurs on the treeview of the masterpage I am not sure how to reference the content page's ModManager.IsDirty property.

From within the MasterPage, you should be able to cast the page to IModWatcherContainer and access its members:
IModWatchContainer mwContainer = this.Page as IModWatchContainer;
if (mwContainer != null && mwContainer.ModManager.IsDirty())
{
    // The page is dirty
}
Mar 17, 2008 at 3:08 AM
Edited Mar 17, 2008 at 3:09 AM
The thanks still keep flowing.

I have implemented a ModAlertDropDownList and it works as you said. Beautiful!!!!

Thanks for you code snippet on referring to a content page from a master page, it also worked!

Unusually I have no other requests (at the moment).

Thanks again for the Top Class Extension.
Mar 17, 2008 at 5:01 AM
Well, it didn't take long.

I am still learning the difference between client-side and server-side ASP.Net programming.

I was implementing the IsDirty server-side function until it all fell over when it was deployed to a test server - can't use MsgBox to get user input.

Because MsgBox doesn't work on the client side I need some way for the click on the TreeViewNode to check for changes and display a message if changes need saving. I know in your earlier post you said this was difficult, but have you had any further thoughts on how to include this into the ModWatcher Project?

Thanks
Coordinator
Mar 17, 2008 at 6:19 PM
I can look into adding something to the project for this. My knowledge of the TreeView control is limited, but I can't say that I can think of an approach short of implementing my own TreeView control that is flexible enough in to be included in this project.

For your situation, I would still lean toward a modified version of my previous post. You could implement the javascript function RedirectIfNoChanges shown in the sample web application, but the problem you face is with DataBinding. But if you handle the TreeNodePopulate event of your TreeView, you could alter the NavigateUrl when the control is databound. Something like this may work:

protected void treeView_TreeNodePopulate(object sender, TreeNodeEventArgs e)
{
    if (!String.IsNullOrEmpty(e.Node.NavigateUrl))
    {
        string newUrlFormat = "javascript:RedirectIfNoChanges('GroupName', '{0}');";
        e.Node.NavigateUrl = String.Format(newUrlFormat, ResolveUrl(e.Node.NavigateUrl));
    }
}
Mar 19, 2008 at 3:38 AM
After a little research into the TreeView control I can see that the client-side events are of no use for trapping a click event. I am looking at implementing your ideas.

Thanks again.