Asp.net User Control with underlying control editor functionality - asp.net

ASP.Net 3.5
I want to create a user control that contains the ListView and DataPager controls along with some custom code in the ItemDataBound that is generic and deals with UI styling.
Ideally, when the developer uses this control, I would like to retain editor support so they can select a datasource, add/remove columns, etc...
Is this easy? If so, any references on how to do this?
If it is not possible, what alternatives are there?
The reason I am trying to create the user control is to make it easier on the developers to retain the ui look and feel and to encapsulate common UI styling code.

You'll need to use the Facade pattern to delegate the exposed designer properties to the composed inner controls.
In my opinion it's honestly not worth the effort it would take to wire up nicely.

Related

Webparts asp.net

What are the disadvantages to using webparts in asp.net? Are they losing their popularity?
I was planning on creating a user defined Dashboard and was thinking of using Webparts, is this the way to go or is there another way of doing customisable dashboards these days? I would prefer not to have to use a 3rd party product.
To me, webparts are more of a sharepoint thing these days.
Other than that, with some design you can get all you need with user controls and some classes of your own to get common functionality and layout sorted out.
Say you have a base class called DashboardWidget that inherits from WebControl here you could define a overridable method
ProcessDataSource -> executes a query to a database or service and formats the results for presentation
And in the prerender method (or something similar along the asp.net lifecycle) you call ProcessDataSource (you could use the DataSource property most controls already have).
Then you inherit from DashboardWidget to make your controls and in the render method you override ProcessDataSource to get the info the way you need and the Render method to setup what to display.
Ideally you should define your own data source class to have a single place to define where to connect, how, credentials, etc..
As for the layout, newer versions of asp.net include several layout option you may use (and there is always pure html if you want)
I'm shooting from the hip a bit here, but that's a way to do it without involving webparts, that to me, are not that popular outside of sharepoint.
Hope anything of this helps

asp.net Pattern for handling View/Edit/Insert situations

I am an asp.net beginner and thinking about designing a website with a typically Master-Detail view. There is a GridView-Control which is displaying all Records and Detail view below to edit existing records, add new ones and display one in detail.
There are several controls in asp.net which can handle such situations: GridView in combination with DetailsView or FormView. But all these approaches do have in common that they seems to be designed for Rapid application development. I want to use my own DAL and so on, so I need to have full control over Insert/Update statements for example.
Whats the typical asp.net approach for dealing with this?
Should I create a UserControl for the Detail view which saves its state (View/Edit/... mode) on its own? Furthermore the view differs only slightly with its state (for example the Insert view does have one more Input-control than the edit view). It seems that the mentioned DetailsView and FormView cannot handle this either and so I have a lot of copy&paste like code.
I think thats all a pretty common situation. What do you prefer in those situations?
You can bind manually data from your custom DAL to the DetailsView or FormView directly like so:
this.dvw.DataSource = new[] { DAL.GetObject(1) };
this.dvw.DataBind();
Or you can also use the ObjectDataSource, which wires up to your DAL object and invokes the method when it needs it.
You can also use a custom user control and load the data manually, which is an approach I have taken in my applications too.
It really depends on your architecture, what you want to achieve, how complex your object model is, and a variety of other factors.
For the Master part, I build the interface by hand, I mean, creating textboxes, labels, etc.
For the Details part, I use a editable GridView. This a tedious task.
Of course, you can use some scaffolding to generate ASP.Net code for your UI from the database model.
You can check this: http://codepaste.net/b1geac

Options besides FormView for data binding web forms

I don't much care for the template rigmarole of the ASP.NET FormView web forms control. It seems the only way to access template defined controls is to 'capture' module level references to the wanted controls in the ItemCreated data binding event, for use in other tasks and event handlers.
Ideally I would just like to be able to call set this.DataSource and call this.DataBind on a page, but only the latter is possible through inheritence, and doesn't achieve any of my normal data binding needs.
What else is there besides the hairy, scary FormView control?
There is the DetailsView control which renders a 2 column table to setup a form. Very uniform control though, so there is limited flexibility if you need that.
Are you looking for all .NET framework or also any OSS or third party?
HTH.

Dynamically creating many instances of ASP.NET usercontrols: How do I create it, and where will my conflicts be?

I haven't seen this implemented before in ASP.NET, but am thinking about a UI that would look and act like this:
Conceptual Overview
A TabControl is loaded and the first tab contains a grid
When a row is double-clicked, a new tab is created with the record detail
The content of the tab/record detail is created by a usercontrol
Many tabs could be created, and therefore many instances of the usercontrol will be created
I know ASP.NET will rename my (runat="server") ID's for me, and that I can use jQuery or ASP.NET server-side code to work with the ID's... My concerns are:
How can I ask ASP.NET to generate a unique ID for each Nth instance of my usercontrol (to be rendered in a placeholder)
How do I actually create that extra instance of the control?
What else do I need to keep in mind?
Since I don't want postbacks I'm considering basing my implementation off of ComponentArt's Callback Control, and using ASP.net usercontrols to achieve this effect. This will allow me to do most things that require a postback, but won't refresh all the elements on a page... just the section that contains the user control. That being said, I'm not tied to a particular implementation.
You should look into the Page.LoadControl method. It works nicely and as far as I remember you put placeholders on your page and load the controls into the PlaceHolders, that's how you control the ids.
One thing that doesn't work out so well with this approach is when your control raises events that your Page object has to handle. If your control is selfcontained however you shouldn't have a problem.
This might help you get started:
http://www.codeproject.com/KB/aspnet/LoadingUSerControl.aspx

Are DetailsView /FormView enough rich for Edit and Insert?

I'm wondering are DetailsView/FormView and ObjectDataSource have enough capability for Inserting/Editing your records or not ?
Or better ask you Do you prefer use them or make your form by your own ?
Because some times it's not easy to use them for complicated task , On the other hand when you have a lot of fields , that's over killing make your form by your own.
No doubt you can use asp.net detailsview and formsview to edit, insert, display data. This makes it easier and faster to play around your data, if you are handy with it. Otherwise you may stumble with some typical odds, of which almost all are answered and you can find them over Internet. Conclusion: Once you get with formsview, detailsview they will be your favourite tools! That is what Microsoft wants of developers.
Still there are some points to remember: if you have forms with lots of controls and you need them interact with each other, you need to consider playing around the straight ways of formview, detailsview. In such case, you would feel very easy if you had created your own UI with necessary controls.
Yes, they do. Each of these has an insert/edit template. You can make them work, and they work fine. Have used them in my own applications. Complicated tasks, formview should be able to handle because you have full control over the UI and layout.
If you have a large form, detailsview allows you to specify fields and allows the control to do the work (you simply specify the data and detailsview handles the form), but of course with a custom UI the formview is the way to go, and yes it can be tedious to have to create large forms... but it's something we developers must do, either find or create a form builder control or create the UI markup ourselves.

Resources