.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

Visual Web part with embedded User Control, fields are null

Posted By:      Posted Date: October 16, 2010    Points: 0   Category :SharePoint

I have a legacy ASP.Net application that consisted of a series of ascx user controls which I am attempting to convert into visual web parts.  

I have wrapped each ascx in its own visual webpart and deployed to my site. Within my site I am able to add some of these to my pages and they render properly.

The ones that I am having difficulty with are those ascx user controls that have a child reference to other custom user controls.

For example I have CustomerinfoUserControl.ascx that has many fields within the control, but one is also a custom user control to select the date called DatePicker2UserControl.asx

Here is the declaration within CustomerInfoUserControl  and usage …



View Complete Post

More Related Resource Links

Get context to a control in web part from visual user control


I have a Visual Web Part (lets call it "ABCWebPart").

I'm attempting to create a connection to another web part which means I have to create the ConnectionProvider in the WebPart class (ABCWebPart.cs).

The value I want to set in my AJAX provider interface is a control I created in my visual user control (ABCWebPartUserControl.ascx).

How do I get the context of the TextBox control from my Visual user Control in order to assign it's value into the AJAX provider interface?


Thanks in advance,

- Eric

Choosing Between a User Control or Web Part for SharePoint

SharePoint will only display Web Parts on a page. However, there are publicly available shims that allow you to write user controls and have them be displayed as a Web Part. From SharePoint's point of view, the shim is a Web Part. From the point of view of the user control, the shim is simply a control in .NET that is including the user control

GDI+: A Primer on Building a Color Picker User Control with GDI+ in Visual Basic .NET or C#


Although most developers and APIs use the RGB scheme when working with colors, it's not the only available way to represent or select colors. For instance, the standard Windows color-selection dialog box allows you to work with the HSL color scheme in an indirect way. In this article, the author describes several color selection schemes, and uses GDI+ (via the System.Drawing namespace) to create a component that makes it possible for your own applications to provide a simpler, friendlier color chooser. Along the way, you'll get tips to help you use GDI+ in your own apps.

Ken Getz

MSDN Magazine July 2003

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

How to Fire events on SharePoint DateTime Control in visual web part

Hi All, I am working on visual webpart of SharePoint 2010. I am using a <SharePoint:DateTimeControl> i m trying  to fire OnDateChanged event on it. I am not getting the Appropriate way to create the event. please help me out!!!!   void ToDate_OnDateChanged(object sender, EventArgs e)         {                         if (ToDate != null)             {                 DateTime min = Convert.ToDateTime(FromDate.SelectedDate.ToString());                 DateTime max = Convert.ToDateTime(ToDate.SelectedDate.ToString());                 int noofdays = Convert.ToInt32((max - min).TotalDays);                 txtNoOfDays.Text = noofdays.ToString();             }         }    <SharePoint:DateTimeControl runat="server" Calendar="Gregorian"  

embedded javascript in user control

Hello, I would like to know if it is possible to embed javascript in a user control. I've followed this article advices. It works with a custom server control but not with a web user control. Is there something special to do to make it work with user controls ?Moreover, it would be nice that only one javascript reference (<script src=""></script>) figure on the page if I use the same user control several times on the page. Is it possible ? Thanks, mathmax 

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.

User Control Web Part - The type initializer for 'IBM.Data.DB2.DB2Connection' threw an exception.



I need help, in our SharePoint 2007 project we have created Web Part using VS 2005 & .Net 2.0, User Control. In the user control for one of the drop down list box databinding method we are using data from IBM DB2. It works fine on our local machine, but after Web Part deployment if i open the page then the Drop Down List is empty. I checked the log in the event viewer. I found the following error message in the vent viewer -

The type initializer for 'IBM.Data.DB2.DB2Connection' threw an exception.


Detail Error Message -

An unhandled exception occurred and the process was terminated.

Application ID: /LM/W3SVC/2076212728/Root

Process ID: 26880

Exception: System.TypeInitializationException

Message: The type initializer for 'IBM.Data.DB2.DB2Connection' threw an exception.

StackTrace: at IBM.Data.DB2.DB2Connection.Finalize()

InnerException: System.InvalidOperationException

Message: SQL1159 Initialization error with DB2 .NET Data Provider, reason code 7, tokens 9.1.1.DEF.2, SOFTWARE\IBM\DB2\InstalledCopies

StackTrace: at IBM.Data.DB2.y.f.a()

at IBM.Data.DB2.DB2ConnPool.g()

at IBM.Data.DB2.DB2ConnPool..ctor()

at IBM.Data.DB2.DB2Connection..cctor()

For more information, see Help and Support Center at h

Ajax, Smart Parts(web part w/ ajax support), User Control, and a GridView


So I am playing around with a user control that I created that adds some functionality to a SPList. I have scoured the web looking for a way to get a web part that had a gridview with custom buttons that is bound to certain Items in a sharepoint list. I found Smart Parts and created an Ajax enabled User Control. the problem is that the label is updating but the gridview is not. and on a site note how can I format the Time on Board column to not include milliseconds(the fields are showing up like '1.02:48:31.8633636') i just want 1.02:48 and maybe the 31:

here is my ascx:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="AlertControlWebPart.ascx.cs"
  Inherits="AlertControlWebPart.AlertControlWebPart, AlertControlWebPart, Version=, Culture=neutral, PublicKeyToke

Visual Studio Designer does not display custom control with embedded image



I am developing a custom control which includes an embeded image to display in the design mode of the control. The Visual Studio designer does not display the image of the custom control. Here is the html generated by the overloaded GetDesignTimeHtml() function:


<div style='height:30px;width:215px;border:5;'><input type="text" value="[DropDownListMultiColumn1]" style="height:25px;width:175px;margin:0;padding:0;border-spacing:0;" /><img  src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA0AAAASCAIAAAAPCcNlAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAEpJREFUKFNjPHDgAAMh4ODgwABU9x8vaGhoAJkDUQckcYEhqA4tfCA+w+4PuFK493H6FxJYhNWhBeQQDD+sSQHhDyALPyCUPpHkAUdqnQngjlwtAAAAAElFTkSuQmCC" style="height:20px;width:15px;margin:0;padding:0;border-spacing:0;" /></div>


This markup displays as expected within an html form. However, in Visual Studio, it shows a red x where the image should be displayed.

Create user control fields based on bound properties



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.



ASP.NET DropDownList Web Control, Part 1

Anybody with much experience in ASP has written an include file function for populating the contents of a SELECT dropdown list with entries from a database. Some of the more advanced users have even gone so far as to add caching to their function to reduce database hits for these rarely changing menu options. Naturally, these same techniques are going to be used with ASP.NET, but with a new programming object model. ASP.NET provides a web control, the DropDownList, which can be used for the same purposes as our custom built SELECT tag from Classic ASP.

Building Re-Usable ASP.NET User Control and Page Libraries with VS 2008


I am having problems with a user control. I want my solution to have a separate project for holding my user controls.

The main project can get a reference to this user control project and can import this user control dll into my main project. 

Thanks in advance,

Dheeraj Mittal


Multiple Instances of User Control


I have a user control that I place on a page severl times.  When I make a selection on a ddl in one one control the SelectedIndexChanged event fires for all the control on the page for that ddl.  So I get duplication of an insert that I do.  Is there a way to make sure these events are isolated so this doesn't happen.


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>

Persist data in a dynamically populated ListBox in a user control


Hi All,

I am trying to persist data in a dynamically populated ListBox in a user control. Here are the details

I have a user control which contains a a listBox and button. On Page_Load of user control I am populating the ListBox control with some values. On Click of button, I am trying to fetch the values which I have selected in ListBox. Though this seems very simple and straight forward I am unable to fetch values.

My Page_Load Function

void Page_Load(object sender, EventArgs e)










My Click Function

Protected Void Button1_Click(object sender, EventArgs e)


       string strValue = listBox.SelectedValue



I have placed brake point at Page_Load and on click function, I am seeing that the moment the breakpoin

Category attribute of user control property does not work correctly in categories tab.



I have a User Control (ascx) and a property which a want to display in my categories tab in Visual Studio in the category named "Styles".

[Category("Styles"), DefaultValue(""), Description("The value for formating something.")]
public String MyFormatProperty
set { /* the code for set */; }
get { /* the code for get */; }

And here is the problem: Actually I do not need a get, because I only have to set the property (write only property). But when I omit the get, the property is displayed in the "Misc" category in the categories tab in Visual Studio. Only when I code the get as well, then the property is displayed correctly in the "Styles" category in the categories tab in Visual Studio.

Does anybody know why? How can I display the category correctly only with set?

Thanks, S.

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