Custom Data-bound control help - asp.net

I have never done this before and am very beginner in this one, so please treat me that way and help me. Obviously this is a complex topic for me at this stage.
I need to develop a custom data-bound control which will contain, few text-boxes, drop-down lists, labels, and other standard web-server controls. And, I want to be able to load this control from a web page on button click. When the user enters any data to any of its child controls, i should be able to save, and also retrieve when the data-bound control is loaded again. Also, the data in the child control should retain their value on postback.
Can someone help me getting into building this? What approach should i follow? Any books or artilces matching my requirement will be really helpful which i can read and help me develop this.

Here is an example of a custom data bound control: http://msdn.microsoft.com/en-us/library/ms366540.aspx
Just out of curiosity, using a FormView or DetailsView control wouldn't solve the problem you are experiencing? It has to be a custom control?

Related

ASP.NET dynamic controls data exchange in postback

Please excuse me for a probably low quality of this question, since I'm not a web dev, so I possibly don't now some obvious things and don't know what to Google for. I think problem must have some simple solution, but I'm struggling with it for two days now, so I feel myself pretty stupid :-).
I have a custom control which is a set of checkboxes which are added dynamically based on a property which is set in OnLoad event of a page. I have two such controls on a page and second control items should be based on items selected in first control.
The problem is, I can't figure out, how to catch on autopostback which boxes were selected in first control before second contol is constructed to pass this data to it?
Take a look at this.
http://forums.asp.net/t/1440174.aspx
Since your building them dynamically, they are not as easy to find as webforms would like to be, if you added them to the page and wired up events and such.
Your going to look at the Request.Forms list, and search thru it for any controls you want.
I believe checkboxes are like radio buttons, they only return if they are checked, which is good, cause you want to know which ones were checked.
I've used same solution as in the accepted answer for this question: Dynamically Change User Control in ASP.Net , just need to assign an unique id for each dynamically created CheckBox in custom control. Not as clean solution as I want but at least it works.
You can save the data in the ViewState, QueryString or as Session before moving to the next page and you can do modifications based on it.

FormView or not?

I have an ASP.NET page with a Wizard control containing several pages of form fields. The data is collected and inserted to a database from the code behind page. I need to set this form up so you can not only insert, but edit a record as well. Since the form is long and complex, I would rather use the existing one and not make a duplicate one for editing, especially since I want to keep both forms exactly the same and any edits would have to be made to both. But it looks like this is what I need to do if I'm going to databind it. But this would also involve putting the Wizard inside of a FormView, and then I'd have to use FindControl to access any of the fields which would mean altering all my already-existing code (which of course would be time-consuming). So should I manually enter all the values from the code behind instead of databinding it? Which is better, to use a FormView and have duplicate forms (plus have to go in and redo the way I access the fields), or to do everything from the code behind?
I cheat in this circumstance. :)
Create each screen as 2 separate user controls
One for edit, and one for view
Then you get access to all you usual coding
Then embed the controls into the Wizard/FormView
I would suggest you to Go Ahead using FormView, as using DataBind control you have more control the functionality and layout Insert/Edit/View template. Since you have specified that your form is very complex and long, if you control from code behind you have to do lot of work to handle this in code behind and lot code required.
Since I have personal experience to develope very complex form using FormView and it was easy for me bind the Value in directly in formview instead if you assign/Get Values of each conrol in code behind and sometimes you have to hide.

thoughts on asp.net grid controls

All, I am creating a web application and I need to give users the ability to add/edit/delete records in a grid type control. I can't use 3rd party controls so I am restricted to just whats in the box for asp.net (datagrid or gridview) or creating my own. Any thoughts on the best direction to go in. I'd like to keep the complexity level at a dull roar :)
thanks in advance
daniel
You should definitely use edit and insert templates. All you have to do is give the button/link the command name such as insert/delete/update and you can allow the Grid to do most of all the work.
Check out this link
I think you'll learn to love the gridviews because they are pretty powerful.
Gridviews have different item templates that you can use for editing and inserting data. That'd be an easy way to go about it.
As long as you set your datakeyid property to the primary key in the database, you should be able to make template fields based off of whether or not you're editing or inserting data. The command name of the button you use to fire the event will handle the statements required for updating/inserting data.
This is a good site for some examples.
the out of the box grid is not too bad.
Here are a few links on master detail records in asp.net this should get you started on the CRUD opperations.
http://www.exforsys.com/tutorials/asp.net-2.0/displaying-master-detail-data-on-the-same-page.html http://msdn.microsoft.com/en-us/library/aa581796.aspx
http://www.bing.com/search?q=asp.net+master+detail
this is the best site for what you are after
www.Asp.Net
Data Access Tutorials controls
Master/Detail Using a Selectable
Master GridView with a Details
DetailView
Using TemplateFields in the GridView
Control
Others
Beginners Guide to the GridView
Control
The GridView Control
IN-DEPTH LOOK AT THE GRIDVIEW CONTROL

ASP.net: How to handle events from dynamically added controls?

So I have a number of user control dynamically added to a page, and user interaction with these dynamically added user controls need to be handled by the control's parent.
Is this what is referred to as "event bubbling"?
How do I do that in VB?
Thanks in advance.
First, you have several complex issues here and my initial thought is that you should separate them and attack each on its own until you have it working and then add them into the final solution. For instance, don't try to start off by dynamically creating your user control and getting it to expose and fire an event. The dynamic part of this problem could get in the way and cause your events not to work but you would never know which is the problem. Instead my recommendation is you focus on events in VB.NET and getting them to work from a statically created user control. Then once you have this all working, move to making the user control dynamically created.
As far as understanding events in VB.NET, I highly recommend the MSDN samples. Start with this simple example: How to: Raise an Event (Visual Basic) and then follow through with the other samples that are linked to from that page. Then once you have learned creating your own events in VB.NET, then look into adding a usercontrol dynamically.
Event bubbling is when a parent control handles an event from a child. So, yes, this is what you are trying to do.
I am not sure of VB but in c# you can use following
id.event+=eventhandler yourEvent;
My first response to this kind of question is always this - why are you dynamically adding the controls? Could they go into a repeater (where this becomes a lot simpler), or must they be programatically handled?

DataTable and javascript

Is there a way to avoid postbacks with gridview every time a row is added to it?
In other words, can I store the DataTable on the client and pass it on to the server control when I am done to save, rather than do postbacks every time the row is added?
I searched and searched....all I could find was web services, JSON, and I have a feeling it's redundant here...it's a simple task I am sure everyone had to do at some point.
Can anyone shed some light on this?
There is no avoiding postbacks if you're dealing with a standard ASP.NET GridView that utilizes ViewState.
You can however, disable ViewState and manually (programmatically) render the control on every page load. This will let you control every aspect of row creation/removal/updates, but you'll have to do it all manually. And yes, you'll utilize AJAX to read from or update on the server.
I don't konw of anything that lets you do that with the gridview out of the box, except the UpdatePanel, but that doesn't really count. If you want to implement I a full AJAX grid I would look into using the ListView Control, which will give you much more control over the resulting html.
Heres a great article from MSDN Magazine http://msdn.microsoft.com/en-us/magazine/cc337898.aspx

Resources