.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Create user control fields based on bound properties

Posted By:      Posted Date: April 10, 2011    Points: 0   Category :JQuery


I am creating a user control that I would like to be able to generate the form entry fields based on what custom data object the form is bound to. Basically, I have a drop-down box that allows the user to pick what type of data object they are working with (user, address, etc.) That choice will bind the user control to the related data object. No big deal there. I am stuck, however, on how to generate the form fields based on the properties of the object. I feel like I have seen examples of this in WPF but am not able to find them now. All form fields will be simple label, textbox combinations in a stackpanel.

I know more detial will probably be required. Let me know what specifically you would like to know. Any help of direction is greatly appreciated.



View Complete Post

More Related Resource Links

how to set read only properties to the particular info path form control based on user logged in?

how to set read only properties to the  particular info path form control based on user logged in?

how to get an array of all the asp.net textbox control inside create user wizard control?



How can I get all the textboxes inside a create user wizard control using getElementsByTagName().

Below is my JQuery code:

<script type="text/javascript">
        function addLoadEvent(func) {
            var oldonload = window.onload;
            if (typeof window.onload != 'function') {
                window.onload = func;
            } else {
                window.onload = function() {

        function prepareInputsForHints() {
            var inputs = document.getElementsByTagName("asp:TextBox");
            for (var i = 0; i < inputs.length; i++) {
                inputs[i].onfocus = function() {
                    this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
                inputs[i].onblur = function() {
                    this.parentNode.getElementsByTagName("span")[0].style.display = "none";



<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>

asp expression bound to user control parameter?


How can I get pass the DataKey of a GridView to a usercontol, preferably without code behind.

Why doesn't this work:

<ucOrderDetails:AJAX_OrderDetail ID="od1" runat="server" OrderNumber='<%# GridView1.SelectedValue.ToString() %>'  />

GridView1 is just a list of orders with a DataKey of OrderNumber.

od1 is not inside of a databout control, does it need to be?

User Control not accessing the value of the properties send to it from the aspx page.


I have a dynamic accordion on a page. Set its datasource to an object of paged data source.The user control is in the accordions content template. When i was writing code the properties were showing but after giving the values of databases as


<uc:UserControl1  runat="server" Property1='<%#DataBinder.Eval(Container.DataItem,"columname1")%>' Property2='<%#DataBinder.Eval(Container.DataItem,"columname2")%>'  ></uc:UserControl1>


but the values shows null, these properties are shown as textboxes text property by user control.

MoreOver when I checked the values of database Items.So i made a textbox instead of usercontrol here as

<asp:TextBox ID="txtTest" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"Columname1")%>'></asp:TextBox>

It is showing the correct value. And if i pass the value directly it is also showing correctly like

<uc:UserControl1  runat="server" Property1="XYZ")%>' Property2="ABC")%>'  ></uc:UserControl1>

. where I am wrong

the problem is eval is not passing the value to usercont

Problem with User Control Properties


I've been trying to figure out a problem that I've had for the past week and believe that the issue is something with a user control that I created. In short, the properties for the user control are recognized by intelisense when I register the control and then add it in the markup for a page. However, the values that I set in the markup are ignored by the class as if the properties don't exist.



Parent Page

 <%@ Register Src="../../controls/contactdetail.ascx" TagName="ContactDetail" TagPrefix="tfc" %>

<tfc:ContactDetail runat="server" ID="UserControlContactDetail" Title="Contact-Detail" ContactId="1580" EnableViewState="true" />   



User Control Class

Imports System.Data
Imports System.Data.SqlClient

Partial Class control_ContactDetail
    Inherits System.Web.UI.UserControl
    Public Property ContactId() As Integer
            Return _ContactId
        End Get
        Set(ByVal value As Integer)
            _ContactId = value
        End Set
    End Property
    Private _ContactId As Integer
    Public Property Title() As String
            Return _Title
        End Get

Create a dimension based on 2 fields

Hello I have a table as follow: No   Placestart    Placeend 1      DK                USA 2      UK                USA 3      USA              DK Now, I want a dimension called Country, which selects either of the rows where a value exist In SQL it would be ex (SELECT * FROM table WHERE placestart = 'USA' OR placeend = 'USA) So, when I select USA in the dimension all 3 rows are listed, as USA is included either in placestart or placeend. If I select DK row 1 and 3 is selected etc... Is this somehow possible?      

Values in user control fields empty when AutoEventWireup=true ?

As a BizTalk developer I'm trying to build a ASP.NET website so some obvious things might be new to me (so please be gentle). I have a web form and I have a user control on it. This user control contains a panel with some user properties that are to be stored in a database. So far nothing fancy. The user control itself contains a panel and is working fine (all code to retrieve and store the values is working). I used the default settings of creating a user control and one of them was AutoEventWireup=true. This works fine because I also have some dropdown boxes (and other fields) that need to be filled with values from the database and that happens in the Page_load event. The panel specifies the 'DefaultButton' which calls a method when clicked to save the values after the user has changed them. On this click the code of the method is called, I confirmed that, but I found out that the values of my controls on the user control (for example the Textbox control) are empty. As a non-ASP.NET developer I couldn't figure out why. So I changed some settings like AutoEventWireup to false. Off course this resulted in my dropdown boxes no longer to be initially filled, but my surprise was big to find out my controls actually contained the values the user typed in. Logically I need both the values and th

Best way to create a collection of User Control objects?

Hi, I'm completely new to WPF (this week) and still grasping C# and .net as a whole. I've created a User Control which I need to add (and be able to remove) multiple instances of into a vertical list. I've so far stuck this in a Listbox although I might change this later when I'm more comfortable. So when I add the object I've created as a ListBox item it displays fine, but my issue is I need to able to delete items and add items and have those items auto update etc - so I'm guessing the WPF way to do things is to build a collection and have it bind to the list box. My question is this, what is the best type of collection to hold such objects. I've tried an Observablecollection so that I can monitor changes but when I give it a.Itemsource = Observablecollection it just presents me with a list of <Collection>. Anyone any ideas?

Need advice to control Privileges based on User

I'm a WinForm beginner. My main form is frmMain.cs Once user logged, frmMain.cs will display a menu based on User. This menu represent in button. Let's say, if User=System Admin then 3 button appear. if User=Master Agent Administrators then 5 button appear and so on How to control that? Really need advice If there's another way, please let me know

Is there a way in VB.Net to embed a custom user control to a web page based on Word or Excel

Hi Everyone.  I'm looking to create a web page that would be used on a local intranet that would use a custom control based on Word and Excel.  I've used code previously to embed it in a Windows application but wasn't sure if anyone knew of any examples out there on how to embed a custom control into a ASP.Net page.

Problem binding business objects to custom user control properties

I have created a user control (supplierPicker) intended to allows a supplier database to be searched and a supplier selected. I want to be able to use this control in a number of other user controls, by binding the suppplierID property of the supplierPicker to a supplierID property in a business object, which is set as the datacontext of the parent user control. When I do this, and there is a supplierID specified in the business ofbject, the binding sets the supplierID in the supplierPicker control and it shows the correct supplier name in the textbox. However when the supplierID DependencyProperty is changed from within the supplierPicker the newly selected supplier name is shown in the TextBox, but the SupplierID does not propogate back to the business object. Other controls on the parent form work fine, so the binding to the business object seems to be ok. Any pointers as to what I'm doing wrong here would be grately appreciated.  This one has been driving me nuts for days! Snipped code for the supplier picker:         public partial class SupplierPicker : UserControl, INotifyPropertyChanged     {         public static DependencyProperty SupplierIDProperty;         public event PropertyChangedEventHandler PropertyChan

Add property to user control design time properties VB windows forms

hi  everyBody,   I've  created a user control that exports a given radGridView to many file formats like Excel, PDF, Csv,... this user control takes the Gridview object as aprobeity Public Class ucExport Private _grdName As RadGridView Private exporter As RadGridViewExcelExporter Private exportVisualSettings As Boolean Dim fileName As String Dim openExportFile As Boolean Public Property grdObj As RadGridView Set(ByVal value As RadGridView) _grdName = value End Set Get Return _grdName End Get End Property End class  how could I add this property to design mode, that's when I click F4, how can I add this to prosperities, rather than code mode  

Tab Panel inside a User control - null referance to text box with set properties

Hi guys, Im having problems with the following: I have a user control which has a tabbed panel inside, I then have a public property which populates a textbox inside the tabbed panel, HOWEVER when I access the property on my ASPX page, it give me a null referance to textbox, I have tried using findControl but still finds nothing, Please help!! ASPX PAGE  <Registration:UserDetails UserID="23" ID="RegistrationUserDetails" runat="server" /> USER CONTROL<cc1:TabContainer ID="TabContainerRegistration" runat="server" ActiveTabIndex="1" > <cc1:TabPanel runat="server" ID="TabPanelAccessDetails" HeaderText="Access details"> <ContentTemplate> <table> <tr> <td>User ID</td> </tr> <tr> <td><asp:TextBox ID="UserIDTextBox" ReadOnly="true" runat="server" SkinID="InputBoxes"></asp:TextBox></td> </tr> </table> </ContentTemplate> </cc1:TabPanel> </cc1:TabContainer> CODE BEHINDprivate int _UserID; public int UserID { set { TextBox tb = (TextBox)TabContainerRegistration.

control the access of data based on user id

Hi, We have a cube (Insurance related project), users are grouped under a windows user group and they have their individual user id's . Now the question is how to restrict the users to view the data only related to them based on the user id(which is included in windows user-group)...?   if any mdx query is needed tell me that also

go back to Create User Step on CreateUserWizard control



I'm using a CreateUserWizard do add users to a web app. Everything is working great, but on thing... the Complete Step :-/

I don't need that extra step, and more, i'm using this control as an option where the administrator of the application adds his trusted users to the site. So, its part of a web form that has a list of users on one side and the CreateUserWizard on the other.

What i tried to do, and was unsuccessful, was to change the ActiveStepIndex back to 0 then the user creation was completed, but this didn't work. The Complete Step still appears. Also, i added this to the continue button event and it did nothing either: CreateUserWizard1.ActiveStepIndex = 0;

Is there any way i can "hide" this step? If not, is there a way to go back to the Create User Step when i click the Continue button in the Complete Step?


Create SPUser object using user credentials on claims based site.



I would like to create SPSite object and pass user token as an argument to make sure all operations are executed with SharePoint security trimming. Inside SPSite I am reading some file content using File.OpenBinaryStream() method.

I am not sure if there is a way to create SPUser using user credentials. I am able to get SPUser by getting it from SPWeb.AllUsers collection using user login name. However it doesn't work for claims based sites as login name for these users looks like i:0#.w|domain\username. 

Am I allowed to user code like this:

SPUser user = web.AllUsers["i:0#.w|domain\username"];

to get SPUser object? I know that 'w' from 'i:0#.w' string means that it is Windows user. What do other symbols mean? Is there any method which can generate login name from user credentials so I may use it to get SPUser from AllUsers collection?

Possibly there are some other ways to execute code for SPSite under some SharePoint user privileges?

P.S. All my code is running out of SharePoint context. I have tried to user windows impersonation but got Access Denied error.

Thanks beforehand for any help,


SQL searches based on user selectable fields


This is the second time I've searched on this and came up not fully understanding why this isn't possible. Say you have one text box, but you want to be able for a user to search by "company name,"  "job number," or "Order No," So you put one text box and a drop down list where the user can select what field to search.

Here is what I would like to do  Select [order_no], [job_no], [company_name] From [order_tbl] WHERE @var1 Like '*@var2*'  (maybe not totally correct syntax, but you get the picture....and @var1 is set from the selection of the dropdownlist and @var2 is set from the text box).

What I do now is three separate SQL statements. If DropDownlist1.SelectedValue = 1 then do, if it = 2 then do, etc.

But when you have a large select statement with table joins, you have to make any changes three times, and it seems easy to make a mistake...not to mention if you have more than three choices, you have an SQL statement for each choice.

Am I misunderstanding that it isn't possible to do a variable field name so I can have one select statement to work with?  And if it isn't possible, I just wish I could wrap my head around why, because it seems such a simple thing to do.


ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend