I am trying to make a custom server control which inherits from DropDownList. I give the control an XML input containing some key/value pairs and my control shows them as a DropDownList.I make the list items in the override Render method like this:
I have ONE <asp:Button ID="btnAddUC" runat="server" ......./> and ONE <asp:Table ID="tblUC" runat="server"...> on my page. User clicks on btnAddUC, user control is added to the page [user can add 'n' user controls to the page]. here I have no problem, adding user controls to the page on user clicks.
My user control has ONE <asp:DropDownList ID="ddlItems" runat="server" ......./> and ONE <asp:CheckBoxList ID="chkItems" runat="server"..../>. I am exposing "ddlItems" by public method, "chkItems" is not exposed. "chkItems" is binded on SelectedIndexChanged event of "ddlItems".
User adds user control to the page, select item from the "ddlItems" ( Note: "ddlItems" is exposed by public property ) , "chkItems" is populated ( using ddlItems.SelectedItem.Value ) . User checks some checkboxes in "chkItems" and then decide to add one more user control. When the second user control is added to the page, checkboxes in the first usercontrol lose their state and apeears unchecked (NOTE: user checked some checkboxes and then added another user control).
I want to put checked beckboxes index in session ( Before another control is added, which event I should use, because at LOAD event there is nothing).
I was able to restict SelectedIndexChanged event to only that user control whcih generated it (checking _EVENTTARGET)
I seriously want to learn how to create a custom server control, for that I made a requirement for myself, but lost on how to accomplish it. Requirement -I want to create a cascading dropdownlist control - which should have following properties -1) ConnectionString - used to get data for the 1st dropdown from database, and also it is used by 2nd DropDown to get data.2) 1stSelectCommand - Used by the 1st DropDown to get data from the database.3) 2ndWhereCommand - used by the 2nd DropDown - uses the selected value from the 1st DropDown in the where clause to get data. Methods - 1) DropDown1_SelectedIndexChanged()2) DropDown2_SelectedIndexChanged(3) CustomCascading_Changed() - this happens when any of the DropDowns index changed. PS - This is a random requirement, of course it got nothing to do with any project or real time.I want to learn, so i incorporated basic concepts like Data Access, Custom Methods, Properties etc.PPS - I know how to create basic custom server control, so plz dont forward me links to how to create basic custom server controls. But in case with extrordinary links.
I have "n" <tables></tables> on my page and each <table> has One(1) <asp:CheckBox.. Enable ='true"/> and "x" <asp:TextBox Enabled="false"..>. Each Table looks as follows
If the exception is thrown , textBoxes are not reset but on postback textboxes appear as disabled (values are not reset)
So here is what happening on postback when exception is thrown
1) Values are not reset (that is what want)
2) Texboxes appear as Disabled (that is what I don't want on exception, REMEMBER I enable textBoxes using client side script)
I have a search page containing a collapsible panel with several controls including text, radio, drop list and check box. In the same page there is a gridview to display search result and links to other pages.Everytime I click on a link in the gridview, the viewstate is only maintained if I nevigate with the pagination of the gridview. However if I click on a link in the gridview and click the back button to the search, everything goes back to default, and the search results will be gone from the gridview. How may I enable the controls and the gridview to remain the same if I hit back button to it?
I want to write own control which can contain other. And I want to define content of the control in the .aspx file where the control is defined. I have written such control. But now I have issue with ViewState of inner controls of my control. The following samle illustrates the issue: I defined two asp:DropDownList ID="ddl1" and ID="ddl2" One of them is inside of my control and other is outside. When posback is occurred asp:DropDownList ID="ddl1 loses state and becomes empty. How to say ASP.net to store state of inner controls defined by this way?
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MyControl.ascx.cs" Inherits="DynamicControls.Controls.MyControl" %>
Using VS2008, .NET 3.5, and C#. The page contains (among other things) a dropdownlist and an objectdatasource. The Page_Load event fires the objectdatasource's Select event. The Selected event iterates through the returned datatable, feed each row into a ListItem, checks to see if a certain column is True or False and, if true, changes the styling for that row to color:red. Finally, the listitem is bound to the dropdownlist. The end users sees all of the dropdownlist items that are false in black and the items that are true are in red. Works perfectly. However, as soon as any item is selected, the page does a postback and the font colors in the dropdownlist revert to the default black. Is there a way, other than rerunning the method that iterates through table and creates the listitems, of maintaining the coloration of the items? Is there a ViewState setting or something?
Here is the dropdownlist and objectdatasource's Selected event:
I have a multiView control within which I have 3 views as part of building a customer order.
Step 1: Customer is selected from gridView and Customer Name is saved in MultiView Session.
Step 2: Products are chosen from gridView. The grid is re-bound depending on which product category is selected in a dropDownList. The product details are also stored.
Step 3: All of the details required to build the INSERT query are passed to labels on a form to be reviewed before committing to db. The next stage, now that I have managed to select multiple rows, will be to display this data in another gridView.
Everything works fine, except for the paging and dropDownList which is causing the checkbox state to be lost after postBack.
I've read a few articles on this, but I think I have made the task more complicated due to the dropDownList in addition to paging. Essentially the customer will be able to select various product lines, across various bindings of the gridView so I need to persist the checkbox state and retain the data for the INSERT query.
how to maintain state of placeholder. i have a placeholder in which i add many image controls dynamically but when my page get refresh all controls from placeholder gets removed from it. the enableViewstate of placeholder is set to true.
'm trying to add validation support to DropDownList by creating a custom control inheriting from DropDownList.To avoid naming conflicts my dropDownList implements INamingContainer. Unfortunately when I try using this control I get the following exception:Unable to find control id 'MDD' referenced by the 'ControlToValidate' property of 'MDD_Validator'This is my control:
I found out that excecption occurs because for INamingContainer FindControl(NamingContainerId) returns null, therefore validator cannot find dropdown.When I remove INamingContainer implementation everything works fine, but then ID given to the validator is not associated with that of DropDown.I know I can manually set validator ID to have DropDown.ID + "_" as a prefix, but is there any way to accomplish this using INamingContainer ?
i have a gridview which consists of databounds and dropdownlist control. When I press the Add Grid Row Button, it will insert a row. Now my question is, if the user selected an item in dropdownList in the firstrow and the user click the AddGridRowBtn Again which will generate the 2nd row, how would i maintain the selectedItem in the dropdownlist after postback?
I have a requirement to create our own MultiValueControls like CheckBoxList, RadioButtonList, DropDownList. I need a headstart, the usercontrols should have all the Even Handler implementation, setters and getters. Also,i will have a table which has the control properties(width, height, cssclass, etc) stored for that control. HOw to dynamically set the properties from the database to the usercontrol. This is required, because the requirement is for the Dynamic Form creation, I store all these ascx controls in the database and all the properties of the usercontrols in another table and map them dynamically.
I'm working with a simple UserControl someone at my company created. It's basically just a DropDownList with a RequiredFieldValidator and some added properties (such as "Required", which controls the CSS styling of the DropDownList and whether the RequiredFieldValidator is Enabled or not).
Here is an example of the UserControl usage where a SqlDataSource is used to populate the ListItemCollection. I'm trying to specify an intial ListItem below (and would like the ability to add multilple ListItems if necessary) but can't seem to get this to work...
My code-behind looks as follows:
I've found several posts related to this but cannot seem to get the declarative ListItem to be added to the DropDownList.
I understand that using a WebControl is another option, but I'd like to learn how to get this method to work if possible.
I have a composite control that returns a different control depending on a property value. The works however I can't seem to set the value of a textbox or the selected item in a dropdown list. Code does not produce error. What am i missing here??
I'm wanting to maintain the dropdownlist values that were selected when i use postbackurl with a button. They cascading dropdowns are on a masterpage in an accordion pane. I select the 3 vales in the ddl and then presss a button which redirects to the new content page.
I've been able to get the values using previousPage.master.fincontrol... but am then setting the selectedValue in the page_init of the conent page, but they aren't set when the page loads... does anyone know where to put the code to set the values?