C# - Creating Ascx Dynamically And Adding Controls To It?
Aug 5, 2010
I have a dropdown list on my homepage which users select a category. After selecting the category, user will fill a form which has related controls to that category in it.
As I have many categories, I just want to have single ascx page and adding controls to it dynamically according to the user choice.
For example: One chose Telephone category, he will face a form having drop down lists asking, what brand? what color? And one chose, book category, he will face drop down lists asking which type? howmany pages?
So 1 ascx must do my work at runtime done as I have alot of categories.
I am going to take these criterias from a database table which has CategoryID and Criteria colomns.
And if I can do that, will it be possible to add field validators to these dynamically created controls.
apologies beforehand for what can possibly be a daft conceptual question. I have an ascx control that has a bunch of ASP labels and buttons in the ascx page and some other public methods and properties in the code behind. When I drop this ascx control in a page it all works fine. I now have a page with a placeholder and I am trying to dynamically create an instance of my ascx control and put it there. I then reference this control in code and while all public methods and properties are available (ie MyControl.TitleString = "Hello";MyControl.DoSomething();) none of the ASP controls are. Rather, they are all null. So MyControl.buttonSave is null, MyControl.LabelTitle is null, etc. Is this by design? Am I missing something? If not, what's the point of being able to create dynamically do this?
I am stuck in chart controls...Here is my prob... There is a ListBox containing some items...when user selects multiple items from the list box I want to generate a dynamic table with the number of columns same as that of the number items selected in the listbox. And for each selected item I want to show a seperate chart in the columns...Currently I want the same chart control for every selected item (i.e. a static hard coded chart that i will replace later by dynamic values)....I am using a method that draws a chart control using a sample dataset... I am calling it each time when a new column is created..Also the DrawChart method executes for the first column only and throws an index out of range exception! after the first execution...my code is not working...here
I am trying to get VS 2008 SP1 to precompile a development site using the Web Deployment Project method. I've done this previously with a different site containing ASPX pages, with success. However, this is a third party example web application containing a set of ASCX controls. The idea is that I want to create a precompiled DLL containing the controls, that can then be distributed as a library DLL. I thought the the use of WDP should allow the compiler to compile all the ASCX controls, and then optionally merge them all into a single DLL.
The problem is, the WDP build reports that it succeeds, but the only file generated is the precompiledapp.config file. On closer inspection of the reporting, it seems that the only error reported is:
aspnet_merge : warning 1013: Cannot find any assemblies that can be merged ...
which I assume refers to the DLL merging process at the end of the compile. This that the compiler was unable to find or process any of the ascx controls in the web application, and so didn't produce any DLLs from them.
I don't really understand what is going wrong here. Should I be able to run a Web Deployment Project like this to compile ASCX controls in this way, and if so, what is likely to be going wrong here? Could the ASCX files somehow be protected from the compiler, to prevent redistribution?
I'm developing an ASP.NET application and I'm trying to do the following:
I'm going to have only one ASPX page splitted into two columns. On the left column is going to be a TreeView, and on the right column is going to be something to edit treeview's nodes.
When the user can select a treeview's node to edit on the right column. Depending on the node's depth fields on right column will vary.
I wondering to use ASCX controls and load on right column dinamically using AJAX, for example. Is there a better choice? Can I do that?
I don't want to reload the entire page when the user wants to edit a treeview's node. Maybe I'm going to need an UpdatePanel on the right column to load dinamically ASCX controls, isn't it?
is anybody interesting in share and join to develop callback web controls. My purposes is lower unsynchronized page development cost. I have developed a base class and a set of common controls. Currently, they allowed to be loaded dynamically in a control or ASCX via callback event using sample server side code. Control library code will automatically register javascript and render it on client browser. These controls worked fine in both callback and postback. To load dynamically from an ASCX file.
'ascx1.ascx contain some callback-able controls Private Function LoadAscx_DuringCallback(Optional ByVal RenderMe As Boolean = False) As String Dim rt As String = "" div1.Controls.Clear() Dim c As Control = LoadControl("~/Test2/ASCX/ascx1.ascx") c.ID = "ascx1" div1.Controls.Add(c) If RenderMe Then rt = CallbackManager1.RenderControlHelper(c) Return rt End Function Or to load dynamically as a control 'c is a callback-able TextBox Private Function LoadControl_DuringCallback(Optional ByVal RenderMe As Boolean = False) As String Dim rt As String = "" div1.Controls.Clear() Dim c As New ACT360_CallbackControls.ZYH.TextBox AddHandler c.KeyUp, AddressOf TextBox_KeyUp AddHandler c.GetFocus, AddressOf TextBox_GetGocus div1.Controls.Add(c) If RenderMe Then rt = CallbackManager1.RenderControlHelper(c) Return rt End Function
I have an issue with gridview and ascx's inside. Into the item template I'm dynamically loading ascx files depending on the row hiddenfield value. Ascx control is then "opened" in panel with modalpopup extender. The issue is ascx control with ceratin programming logic behind does not postback in this scenario.
I'm developing an ASP.NET application with C# and Ajax.I have a page that holds user controls loaded dynamically. I need to pass some data (integer values and some strings) to the user control that has been loaded dynamically.Now I use Session to pass these values, but I think I can use another way; something like VIEWSTATE or hidden input.What do you recommend me?The fact that I load the controls dynamically is important because controls are loaded on every postback, and I can't store any value on controls.
I would like to add an event: clicked. I want to let the user add this control on the page and attach handlers to this event so that when this control is clicked it is possible to do something. It might seem a strange solution, it's like i'm trying to invent again the button control, that is: my custom button.
Well to fire the event I would like to add a javascript in my div and call a js function that calls, using ajax mechanism, a server side function. Well how to call a server side function from here.
I posted a question about how to call a server side function from a client side one and got some answers (many of them told me to use PageMethods), well it seems that pagemethod does not work, it compiles but when running and clicking on my control and executing the js (in the line PageMethods.mymethod()) here I have an error --> Java script exception: unrecognized method. It seems not finding the PageMethod.
Is there a way to add .ascx files to a sitemap such that it will load/unload the controls based on the last ones visited? The problem is i have a page that contains a few controls that get placed under one another, and i'd like to just be able to jump between them with the sitemap instead of creating a new page for them... this is what i'm trying to put into the sitemap without luck (see Product List, Product Detail):
Ive got some custom code that im using to load user controls dynamically depending on the option a user selects from a menu control on the page.
I wanted to create an admin page that can be used to provide a one stop shop to complete all actions within an app im building, (like a template/iframe scenario that loads all selections in a screen on the right)
My code works, however when the user has completed an action sucesfully within one ascx, then selects another from the menu on the left, it wont load the new control, it comes up blank like it hasnt refreshed properly meaning that they have to close down the page and reopen it. (which is very annoying)
My codes below, can someone take a look and see if they can see whats wrong.
I am not able to get the htmlinputimage control id created dynamically based on no of rows reterived from db.
these controls are bn created in usercontrol (.ascx.vb) page
The actually requirement is ...there are set of images in a table, i need to get a particular image src, based on that i need to collect the image id(s) and use it for futher process...
and this is poosible using a FindControl... which i have bn trying , but all invain...
Can I dynamically create controls in Silverlight without a postback to the server (even an asynchronous one). Does silverlight drag-n-drop requires postback?
I'm asking this because I've an asp.net application where I dynamically create/delete lots of controls. So after the postback I'm getting error with view state stating that the control tree doesn't match the view state tree.
I have a GridView with a column of checkboxes. I also have a panel pnlSubmitOffer which serves as a modal dialog with ajaxToolkit:ModalPopupExtender:
[Code]....
I need a set of controls (text boxes and datetimepickers) to appear on the modal dialog based on how many checkboxes in the GridView are checked, i.e. a set for each checked record. Thus the controls should be added to the panel dynamically. But I don't know how to do it, as btnSubmitOffer click is not handled, because the modal dialog appears first. I was told that the controls can be added dynamically using javascript, but my knowledge of it is not enough.
I have a requirement in which i want to create an aspx form in which I want to define the name of the controls in the xml file and on the basis of the xml file i want to create the aspx form. if in the xml form there are 10 controls then dynamically 10 controls will be created i have following type of xml
Never really worked with the asp tables but for this project it makes more sense, I am having trouble addding rows dynamically from the sql datatable i am pulling. In hte datatable it has 12 rows with 14 columns, I need to make this into a table, with a dtagrid I would be done but I have to pull other data that they could add columns, so a table I am told is easier.
This gets my data and I can see it
mydataTable = new DataTable mydataTable = GetData(sql) mydataTable.add.row(myDataTable.rows(0)(0))
I get nothing but errors trying to do this, what is the correct way to add rows to an asp.net table
Can I add this all to a datagrid and then add the extra columns I need if they are there with out using a table.
It seems when I try to dynamically create multiple instances of a User Control, I get an Object Reference Not Set To An Instance Of An Object error on any ASP control that I'm using in that User Control
Here's the class where I'm creating them.
[Code]....
Am I able to successfully refer to a panel on the page that I'm calling this routine from simply by ByVal ... As Panel, or should I use HttpContext?
I have created a control with two standard asp controls in (a label and a Textbox).I want to have access to the controls within but also be available from the designer so that the label properties can be prefixed with Label_ etc for example
[Code]....
How can I create a property from this reflection list?
i have a lable a textbox, and two buttons(+ and - button) on my asp.net page.
so when i click on the plus button it should add the the whole collection of controls to the page(i.e. lable, textbox and two buttons). And when i click on minus button it should remove the collection.
This should go on.meaning whenever i click on any plus button the control collection should get added to the page.
I am wondering what will be the best approach to do it.
I want to create columns in gridview dynamically based on rows in a table and each gridview colum should have a checkbox. When I Click the save button, I want to save the checkbox state. How Can I do this ?