So, I have three drop down lists that are related to each other:
CountryDDL
CityDDL
ZipcodeDDL
Obviously the options in the CityDDL are created when the CountryDDL's OnSelectedIndexChanged event is fired, and ZipcodeDDL is created when the CityDDL OnSelectedIndexChanged event is fired.
That's all good....but what I'm wanting to do is dynamically insert multiple instances of these related controls.
I need to be able to click a button and add as many instances of these three related drop downs as a user needs.
Any ideas for best way to accomplish this preserving state and having all events work as they should??
I'm using .Net 4.0 and the current Telerik release.
Put your controls into a user control or custom web control and implement the logic for the simple control dependency. The hosting user or web control acts as naming container and all will work fine if you nest this control in an outer control like a repeater or grid.
Related
I am pretty new to ASP.NET programming. Now I try to add several web user controls to my page dependent on checked boxes in a tree view that I create from data of my database.
I was thinking about using iframes - one for the tree view and the other one for the controls, but this seems quite complicated. Is there an easier way to do this?
The tree view should always remain on the page an the web user controls should appear or disappear in a scrollable part of the page. Could you tell me what would be good practice to resolve this issue?
iframes would not be the easiest way to go about this (as you have two different server side pages that cannot communicate with each other).
If the number of controls that you are controlling visibilty for is not large, I would suggest that you have your user controls in a panel on the page, all invisible, and the treeview and this panel all on the page, within an update panel.
On check of the treeview, in the partial postback, show/hide the appropriate web user control.
As noted above, dynamically adding controls is problematic, as they have to be re-added every postback and you run into state issues.
Dynamic controls added to the page need to be added back to the page on every postback. I would not use iframes for this; instead, you can have the tree view on the left in a floating div, and another floating div for the right content. If the right content is always checkboxes, use a ListView, Repeater, or some other data bound control that builds the control tree for you. It's much easier to work with these controls as long as the UI is consistent. If not, you can build the right side dynamically. You'd have to readd the checkboxes to the page on all future postbacks.
Basically I have created a user control containing a Telerik RadGrid, inside the control I have another two controls that have Telerik RadGrid inside them. I am trying to bind the modified data back into the User Control inside the parent user control. I have checked that the data is correct after they have been edited but when the form is binded again the inner controls have the same data as the form is first loaded. I am using RadWindow. Coworkers have suggested that it works with asp.net form controls however it seems that there is an issue with Telerik controls. Is there a easy way to force a rebind of the control?
There is a Rebind() method you can call to enforce this. This method causes the refresh and reloads the data and calls NeedDataSource.
Is there anyway to auto-create ASP.NET controls at Design time based on fields in a SQLDataSource? It is really easy to create a form in WinForms by dragging the fields onto the form. You can even determine which control will be used (like a dropdown, checkbox). Is there anyway to do this in ASP.NET? I don't want a DetailsView since I need to have separate controls that are created.
So based on what you have said, I am going to take a guess and say that a FormView would work for what you want. Assuming that you have Insert, Update and a Parameterized Select statement defined for a SqlDataSource, you can wire them up in the designer and Visual Studio will automatically create the form fields necessary.
I'm working on developing a custom control to select items from a predefined list. This is accomplished via 2 ASP.NET ListBox controls, with a few buttons to trigger the movement of ListItems from one ListBox to the other (lets call these ListBoxes lstSelected and lstDeselected).
This is easy enough to do in ASP.NET or JavaScript independently: I have both working. However, if modifications are made via JavaScript, ASP.NET retains no knowledge of this. Is there any way to register the creation of of options in a select tag without AJAX?
You could also do this with traditional postbacks, it doesn't have to be ajax. The postbacks would be triggered by clicking your buttons which change which items are in which listboxes.
You could have a couple of hidden fields, say hdnHasSelectedChanged and hdnHasDeselectedChanged, and set those fields in your javascript code. Then, when a postback really happens, your code-behind can read those hidden fields to detect if changes occurred.
I have a site that I am currently working on in ASP.NET 2.0 using the usual WebForm stuff and ASP.NET AJAX 1.0. Is it possible to bind an event to a dynamically created control after the Page.Load event?
I have a table <td> element that I am dynamically creating similarly to this code:
' Create Link Button
lnk.ID = String.Format("lnkDetails_{0}", dr("Id"))
lnk.Text = dr("Name").ToString()
lnk.CommandArgument = dr("Id").ToString()
AddHandler lnk.Click, AddressOf DetailsLink_Click
cName.Controls.Add(lnk)
This this code is looped over for each row in a database (and of course more cells are added to the table, including an ImageButton with an event. The events work flawlessly when I execute this code during events leading up to and including Page.Load. I need to be able to fill this table with current data, which is updated during a btnClick Event elsewhere on the page, which occurs after this Page_Load event, so I am populating with old data. If I change this code to Page.LoadComplete, events stop working.
This data is a summary display of various components of an application, things like somebody's name, which when updated on a 'detail' form, updates the database by partial postback (a requirement), then it needs to show the update in this 'summary' section after an update. Currently it takes 2 postbacks to actually see the change in the 'summary' section, so effectively the summary is 1 step behind the changes (clear as mud?)
What would be the best way for me to populate this table with current data (which is available during/after Page.LoadComplete), but still have an event fire when a link is clicked (the event causes an UpdatePanel to display the 'detail' form).
I also have jQuery at my disposal and the usual ASP.NET AJAX methods, also javascript is a requirement for the website, so I do not need to degrade for unsupported browsers.
This is my first ASP.NET web application and need some help figuring out the best way to make this happen (I'm well versed in PHP, Django and the usual ways to do web forms - things like having multiple forms on one page o_O).
Update:
There really isn't a good way to bind control events to controls after Page_Load. The overall architecture of the pages is there is one ASP.NET form encompassing the entire page, there is only 1 aspx page. I am using master pages (however it doesn't have any obvious implications to my issue).
The page is split into a left and right 'pane', the left is a summary of all the data (in an update panel), the right 'pane' has 6 'tabs' implemented each as their own user control, each with several form fields and an update button all in it's own UpdatePanel.
An update on any of these tabs only refreshes the summary panel (UpdatePanel.update()) and its own panel. The 'refreshing' and event binding of dynamic controls of the summary from the db happens during Page_Load and the Update Button event updates db data. (The control event happens after Page_Load). I want to avoid doing a double post to get the summary to update, any thoughts are helpful.
You need to postback the whole page after your data changes in the 'btnClick Event elsewhere on the page'. It sounds like you have an UpdatePanel and it sounds like this is catching the postback of your btnClick event handler. Put the btnClick outside the UpdatePanel or change its triggers so that your btnClick forces a postback/refresh of your data. Or, redesign your table so it's AJAXly-refreshed when you click on btnClick, it's hard to get you more details without knowing more about the structure of your page and controls.
Good luck!
You can bind to an event whenever you want. It's just a simple event after all. But not all places might be suitable because you have to take into account when the event fires. And in most cases this happens between Page_Load and Page_PreRender. That includes the click event on a LinkButton. In general, I would recommend to add your dynamically created controls in the Page_Init stage.
You have to add the controls before Page.Load in order to maintain ViewState between postbacks, so use the OnInit event handler for that.
But once they're added, you should be able to bind event handlers (such as OnClick) at any point during or after the Page.Load... for example in your grid's ItemDataBound (or something like) or in the Page.PreRender.