简体   繁体   中英

ASP.NET C# Web Forms - How to make an interactive CRUD page in a legacy application?

I recently added a roles/permission functionality to a somewhat old web forms app in ASP.NET and C#. Now I need two simple functions: add/edit roles, add/edit permissions to roles (permissions are in a table but not modifiable). The tables are somewhat like this (I need an interface for the bold ones):

  • Roles table: RoleID, RoleName
  • Permissions table: PermissionID, PermissionName
  • Roles_Permissions table: RoleID, PermissionID

How can I make them interactive, in the sense of not having a post-back, and having both functionalities in the same page? I visualize a dropdown for the Roles, that when one is chosen, the list of Permissions refreshes for that role, and right there the user can change the permissions, RoleName, or even add/delete a role. The page needs to use an existing master page to match its appearance to the rest of the web app; I do not know if that would limit functionality.

I need the implementation to be as non-intrusive as possible (no strange plugins, and work with current browsers without any configuration on the client side). I found breeze , knockout and angularjs, but can't find if/how I can add the functionality to an ASP.NET C# Web Forms in Visual Studio 2012 (version 11).

What is the fastest/easiest way to build the page, that will be easily maintainable in the future, and be a good starting point to begin "modernizing" the rest of the web app based on it?

You can add a standard blank aspx page to your application and get it working as normal for a Web Forms application. Wire up the navigation, make sure that it picks up your master page (if you are using one), etc.

From here, depending on various circumstances, you can do a couple of things.

ASP.NET AJAX

This was originally introduced for ASP.NET Web Forms, and uses Web Forms controls and a small amount of work in the codebehind to glue everything together. It's less flexible than other solutions, but should be fine for the scenario you cite. This would be the preferred method if you are more comfortable with Web Forms than other programming models. Policies or the structure of the existing application may also make this more preferable.

Single Page Application

You mentioned frameworks such as breeze, knockout, and Angular. So, let's focus on those. Again, depending on your experience, and the app, these might be compelling options. I wouldn't go as far as Angular for the time being, since it's more appropriate for a full rewrite. It could work embedded in another application, but is probably too much work for the scope of your project.

At minimum you could make do with plain JavaScript and AJAX, but you'd need to write a lot of your own code. If you add in a little jQuery, that will help with DOM manipulation and AJAX calls to your services. I've had success in enhancing older apps with jQuery for DOM manipulation, and Knockout for databinding. You can probably make do without jQuery, but I wouldn't. These two libraries don't make any assumptions about the environment that you are using them in, and should be content to be constrained within the limited scope of a single page within a larger application.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM