Latest developer linksBookmark and Share
 
HomeThis WeekTop MonthTop AlltimeSearchRegisterFAQ
  
 
Submit Your Link
Please login to submit your Link
 

Loading User Controls Dynamically

Posted: Nov/02/2009   By: nikhil   Points:15   Category: .NET  - ASP.Net    Views:241   Vote Up (1)   Vote Down (0)    
User Controls are great in ASP.NET. They let us divide the page into small sections. You can easily use User Controls on a ASP.NET page by simply dragging and dropping the control from the solution explorer. Sometimes we need to load the User Control dynamically. In this small article we will learn how to load the User Control dynamically.

View Complete Post


Comments:
Be the first to comment this post.
 
Post Comment
Please login to post your comment
More Related Resources

Changing Style Sheet of Controls Dynamically

  
CSS (Cascading Style Sheets) provides easy maintenance for the look and feel of the website. Sometimes we need to set the style of lot of controls dynamically using style sheet. In this article I will show how you can change the style sheet of the dynamically created label controls.

php user migrating to asp.net

  

Hi, I have a website that I need to add some dynamic data from asp.net, I'm completely new to .net and am having some problems (usually a php user).

K so, I have
a simple html tag
<a href="" title = "" >my link</a>

Now all I want to do is to insert some data in to the href and title parameters. in php I would just use <a href="<?php echo myHrefvar?>" title = "<?php echo myTitlevar?>" >my link</a>

I've tried doing
<a href="<% = myHrefvar%>" title = "<% = myTitlevar%>" >my link</a>

and in my default.aspx.cs I have the variables being set
string myHrefvar = "my href";
string myTitlevar = "my title";

but it always gives the message that they're not linked.

Have also tried
<a href="" title = "" ID=Req1>my link</a>

and in the apsx.cs file
Req1.HRef = "sdsdsd";
Req1.Title = "sdsdsd";

but again I get an error saying Req1 doesn't exist in the current context.

So help, I'm missing something rather fundamental here, any help would be much appreciated.

James


send alert message to user if close internet browser before save web form data

  

 Hi, I have window form to let user fill data, I want to alert user if close web browser before saved web form data, could anyone provide any clue?

 

Thanks,

Martin


How get clientID of a control in a ModalPopup of a User Control??

  

Hi,

I have a user control which has a modal popup. This modal popup has a grid and few controls like textboxes and comboboxes. I am trying to clear out all the controls when the close button is clicked. I am using javascript to close the modalpopup. but to clear the controls, $get('<%=txtbox1.clientID%>') method is returning null. can someone please help me?


Here is my code snippet.

function close_Click() {
    var mdlPopup1;
    mdlPopup1 = $find('modalPopup');
    mdlPopup1.add_hidden(clearInputFields);
    mdlPopup1.hide();
    
}

    function clearInputFields() {
        var name = $get('<%=txtName.clientID%>');

        name.value="";
       }


Create more than 1 set of controls in runtime.

  

I've figured out how to create the controls in the format I want, but now I am confused as to how create more than one set of them. I set everything to new and increment the names of each control, but it's only updating the one set. Here is my code:

  intPnlCounter += CInt(ViewState("intPgCount"))
        
        'Table
        'PlaceHolder1.Controls.Add(New LiteralControl(" <table style=""height: 27px""><tr><td colspan=""2""> </td><td colspan=""2"">"))
        PlaceHolder1.Controls.Add(New LiteralControl("<table style=""height: 27px"">"))

        'Component Header
        Dim lblHeader As Label = New Label
        lblHeader.Text = "Additional Component Item: " & intPnlCounter
        lblHeader.ID = "lblHeader" & intPnlCounter
        lblHeader.Font.Bold = True
        lblHeader.Font.Underline = True
        lblHeader.Font.Name = "Trebuchet MS"
        PlaceHolder1.Controls.Add(lblHeader)
        PlaceHolder1.Controls.Add(New LiteralControl("<tr><td colspan=""2""> </td><td colspan=""2"">"))

        'Item Label
        Dim lblItem As Label = New Label
        lblItem.Text = "Item:"
        lblItem.ID = "lblItem" & intPnlCounter
        lblItem.Font.Bold = True
        lblItem.Font.Underline = True
        lblItem.Font.Name = "Trebuchet MS"
        'lblItem.Font.Size = Unit.Percentage(10)
        PlaceHolder1.Controls.Add(lblItem)
        PlaceHolder1.Controls.Add(New LiteralControl(" "))
        'Item Textbox
        Dim txtItem As TextBox = New TextBox
        txtItem.ID = "txtItem" & intPnlCounter
        txtItem.Width = Unit.Pixel(306)
        PlaceHolder1.Controls.Add(txtItem)
        PlaceHolder1.Controls.Add(New LiteralControl("</td><td> </td></tr><tr><td class=""style11"">"))

        'NSN Label
        Dim lblNSN As Label = New Label
        lblNSN.Text = "NSN:"
        lblNSN.ID = "lblNSN" & intPnlCounter
        lblNSN.Font.Bold = True
        lblNSN.Font.Underline = True
        lblNSN.Font.Name = "Trebuchet MS"
        lblNSN.Font.Size = 10
        PlaceHolder1.Controls.Add(lblNSN)
        PlaceHolder1.Controls.Add(New LiteralControl(" "))
        'NSN Textbox
        Dim txtNSN As TextBox = New TextBox
        txtNSN.ID = "txtNSN" & intPnlCounter
        PlaceHolder1.Controls.Add(txtNSN)
        PlaceHolder1.Controls.Add(New LiteralControl("</td><td class=""style12"">"))

        'PartNum Label
        Dim lblPartNum As Label = New Label
        lblPartNum.Text = "Part Number:"
        lblPartNum.ID = "lblPartNum" & intPnlCounter
        lblPartNum.Font.Bold = True
        lblPartNum.Font.Underline = True
        lblPartNum.Font.Name = "Trebuchet MS"
        lblPartNum.Font.Size = 10
        PlaceHolder1.Controls.Add(lblPartNum)
        PlaceHolder1.Controls.Add(New LiteralControl(" "))
        'PartNum Textbox
        Dim txtPartNum As TextBox = New TextBox
        txtPartNum.ID = "txtPartNum" & intPnlCounter
        PlaceHolder1.Controls.Add(txtPartNum)
        PlaceHolder1.Controls.Add(New LiteralControl("</td><td colspan=""2"">"))

        'SerialNum Label
        Dim lblSerialNum As Label = New Label
        lblSerialNum.Text = "Serial Number:"
        lblSerialNum.ID = "lblSerialNum" & intPnlCounter
        lblSerialNum.Font.Bold = True
        lblSerialNum.Font.Underline = True
        lblSerialNum.Font.Name = "Trebuchet MS"
        lblSerialNum.Font.Size = 10
        PlaceHolder1.Controls.Add(lblSerialNum)
        PlaceHolder1.Controls.Add(New LiteralControl(" "))
        'SerialNum Textbox
        Dim txtSerialNum As TextBox = New TextBox
        txtSerialNum.ID = "txtSerialNum" & intPnlCounter
        PlaceHolder1.Controls.Add(txtSerialNum)
        PlaceHolder1.Controls.Add(New LiteralControl("</td><td>"))

        'Hours Label
        Dim lblHours As Label = New Label
        lblHours.Text = "Hours:"
        lblHours.ID = "lblHours" & intPnlCounter
        lblHours.Font.Bold = True
        lblHours.Font.Underline = True
        lblHours.Font.Name = "Trebuchet MS"
        lblHours.Font.Size = 10
        PlaceHolder1.Controls.Add(lblHours)
        PlaceHolder1.Controls.Add(New LiteralControl(" "))
        'Hours Textbox
        Dim txtHours  

User control does not let me assign values into Text boxes

  

Hello,

Got a problem that I do not know what is going on (using c# and .NET 2008):

I have a main web page and added a user control inside it. The user control has some textboxes. The problem I have is when I populate the textboxes with the data that is in the DB, they do not show the values. The strange thing is If I change the property of textboxes ReadOnly to TRUE, they show the values. The problem is that I need them to be ReadOnly=FALSE.

Could anyone do help me please?

Thanks,

Marco


Microsoft JScript runtime error: Sys.ArgumentException: Value must not be null for Controls and Behaviors. Parameter name: element

  

Hello,

I am facing this error 

Microsoft JScript runtime error: Sys.ArgumentException: Value must not be null for Controls and Behaviors.
Parameter name: element

Microsoft JScript runtime error: Sys.ArgumentException: Value must not be null for Controls and Behaviors.

Parameter name: element

while using Ajaxtoolkit ModelPopupextender with listview, actually I am retriving image from database to the listview in VS 2008. 

Can anyone please help me out of this..


Problem with OnClick event for a dynamically created RadioButton C#

  

Hello,

Im having problems with the onclick event. ive been trying to work out a solution for hours to no avail.

The radiobutton works just fine on firefox, but not on IE. Im using IE8.

I read it is a problem with IE because of GroupName not being defined when dynamically creating controls.

When i placed an alert command in the onclick event. i saw that the radiobutton is being selected. but after i close the alert message, the selection disappears.

Any help would be appreciated.

Thanks.


Visual Studio 2010 Upgrade broke all controls in design

  

I have recently upgraded from VS 2008 to VS 2010 and the conversion process completed successfully.  However, when viewing my design view for all aspx pages, any control i had in there is displayed with the message "Error Creating Control - Object Reference not set to instance of an Object".  If i even attempt to create a simple new button or textbox from the toolbox, the control automatically comes back with that error.  However, in runtime, my controls are all displayed and functioning correctly.

I have seen some posts regarding session state and checking that Context is not null in the OnInIt override method, but I am no using any OnInIt override methods in any of my code behinds.  It pretty standard with usually only page loads.

This is creating a tough time developing because it is not using intellisense when i am looking for events and other actions on the controls.  Also, Javascript does not appear to be functioning the same  since it doesnt seem to be using the FindControl method correctly (Probably because the page is building out the control).

This is very frustrating and i've spent two days on this, so any help would be appreciated.

Thanks! 


Failed to generate a user instance of SQL Server

  

 I am creating asp.net forms authentication. When I run web site and there I try to create new user I get this error:

Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance. The connection will be closed.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

SQLExpress database file auto-creation error:

The connection string specifies a local Sql Server Express instance using a database location within the applications App_Data directory. The provider attempted to automatically create the application services database because the provider determined that the database does not exist. The following configuration requirements are necessary to successfully check for existence of the application services database and automatically create the application services database:

  1. If the applications App_Data directory does not already exist, the web server account must have read and write access to the applications directory. This is necessary because the web server account will automatically create the App_Data directory if it does not already exist.
  2. If the applications App_Data directory already exists, the web server account only requires read and write access to the applications App_Data directory. This is necessary because the web server account will attempt to verify that the Sql Server Express database already exists within the applications App_Data directory. Revoking read access on the App_Data directory from the web server account will prevent the provider from correctly determining if the Sql Server Express database already exists. This will cause an error when the provider attempts to create a duplicate of an already existing database. Write access is required because the web server accounts credentials are used when creating the new database.
  3. Sql Server Express must be installed on the machine.
  4. The process identity for the web server account must have a local user profile. See the readme document for details on how to create a local user profile for both machine and domain accounts.


Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


Stack Trace:

[SqlException (0x80131904): Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance. The connection will be closed.]
   System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +4846887
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +194
   System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2392
   System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK) +35
   System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject) +144
   System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart) +342
   System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +221
   System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +189
   System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +4861315
   System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup) +29
   System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +4863644
   System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +117
   System.Data.SqlClient.SqlConnection.Open() +122
   System.Web.Manage 
 
Categories:
.NET
Java
PHP
C/C++/VC++
HTML/XML
SAP
MainFrames
Data Warehousing
Testing
MySQL
SQL Server
Oracle
Javascript/VB Script
Others
Login
 
 
 
 
 Forgot password
 Contact Us   Terms Of use   Share your knowledge