.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

dynamically add control or register and set visibility

Posted By:      Posted Date: September 03, 2010    Points: 0   Category :ASP.Net
I have a classic asp website that I would like to convert to asp.net. The application is structured such that there is one central page that uses "server.execute" to call a page template and the template uses "server.execute" to call the page functionality. I am thinking that I will create a single asp.net page that sits alongside the current page. I can then slowly convert existing page functionality to usercontrols and add a little logic to redirect to the apropriate page based on the requested page functionality. Should I dynamically add the usercontrol to the page for the page functionality or should I register each control on the page and dynamically change the visibility? We don't add new functionality or update the exisiting functionality very often. Most changes are to the content stored in the database used by the pages.

View Complete Post

More Related Resource Links

using the linqDataSource control programmatically (dynamically)



my scenario is this: I want to use the linqDataSource control to bind data to a gridview for it's efficient built-in paging and sorting features *but* I don't want the data to be bound until the user has input various search parameters, so I need to bind the data from a button click event. Also, the search options will be somewhat complex in that there will be several optional search parameters, via various dropdowns and textboxes, so I can't just declaratively/statically setup all the WHERE parameters on the linqDataSource (at least I'm assuming I can't, or that it may result in poor performance if I do and just assign default values like the everything wildcard '%' for the cases the user doesn't use a particular search parameter). Given that brief description, here is an example of what I'm doing, but with only one WHERE parameter for simplicity, the real code will be adding anywhere from 1 to about 12 WHERE parameters depending on how the user sets the search options in the GUI.

the linqDataSource on the aspx page:

<asp:LinqDataSource ID="ldsMain" runat="server" 
        Select="new (field1, field2, field3, etc..)" 

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

Dynamically load user control without postback


Hi all,

I need urgent help. (c#coding)

In my base page, I have a dropdownlist control which loads different usercontrols on selectedindexchanged event.

While loading these usercontrols, my page postbacks all the page. I used updatepanel but again same problem.

Is there any way to load controls without postback? I Really need help as soon as possible.

Here is my code:

protected void Page_Init(object sender, EventArgs e)
        if (Session["control"] != null)
            string c = Session["control"].ToString();
            if (c == "1")
                iuc = (IlkogretimUC)LoadControl("~/Controls/Ilkogretim.ascx");
                dl.SelectedValue = Session["control"].ToString();
            else if (c == "2")
                luc = (LiseUC)LoadControl("~/Controls/LiseUC.ascx");
                dl.SelectedValue = Session["control"].ToString();
            else if (c == "3")
                youc = (YuksekokulUC)LoadControl("~/Controls/Yuksekokul.ascx");

Want to Create Table Dynamically With text Control in WinForm Csharp

Hello To All... from Many Days i m tryng to create a simple table using csharp in WinForm.Which will include textbox in each cell according the Passed No of Col & Row. but not getting the proper result. Actually i want to trace each cell data and want to save each cell data to data base : eg. in cell 11(1col & 1row) i m having Combobox which having some item list and when the user select the list item the data will save to the database. Regards, Praveen    What is the Key of Life ... Its Sharing Your Thought & Knowledge ...

How can I register a name for a control that is an ItemsControl child?

Hello, How can I register a name for a control that is an ItemsControl child? When I create the controls dynamically in code, the RegisterName works just fine.  However, when those same controls are created by the ItemsControl XAML, RegisterName does not work. Here is the XAML which correctly generates what I want: <Canvas Name="Tab_CanvasTabs"> <Canvas.Resources> <local:CategoryTabs x:Key="myTabs" /> </Canvas.Resources> <ItemsControl Name="Tab_ItemsControl" ItemsSource="{Binding Source={StaticResource myTabs}}"> <ItemsControl.Template> <ControlTemplate TargetType="ItemsControl"> <ItemsPresenter /> </ControlTemplate> </ItemsControl.Template> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <Canvas /> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemTemplate> <DataTemplate> <DataTemplate.Resources> </DataTemplate.Resources> <Canvas Name="Tab_Canvas_X" Tag="{Binding Path=Number}" MouseLeftButtonDown="Event_CategoryTab_Canvas_MouseLeftButtonDown" MouseLeftButtonUp="Event

Dynamically (on client side) populating data control (repeater) when dropdown item is selected

Hello!I'm currently working on a project and I want to make as much things as possible performing on client side - with as little loading as possible.The project consist of three "main" pages. On one page I use jQuery DataTable plugin which is working great. One page has tabs (using jQuery). I want to put datacontrol (repeater) on this site and when  user selects one item in dropdown, data in repeater loads on client side, without performing the action on server.I wonder if this is possible and if somebody can give me some case to help with?Thanks!I hope I was clear enough. all the best

Dynamically Binding Header of Repeater Control

Hi , I am stuck up into following Issue while binding Repeater control dynamically from database I have repeater control which I want to populate from database.. asp:Repeater id="Repeater1" runat="server">   <HeaderTemplate>      <table border="1">         <tr bgcolor="#ffcc99">            <th><asp:label id="Lname" runat ="server" text = "???"  ></asp:label></th> <th><asp:label id="Fname" runat ="server" text = "???"  ></asp:label></th>         </tr>   </HeaderTemplate>   <ItemTemplate>      <tr bgcolor="#ffcccc">        <td><%# DataBinder.Eval(Container.DataItem, "Col1") %></td>        <td><%# DataBinder.Eval(Container.DataItem, "Col2") %></td>      </tr>   </ItemTemplate>   <FooterTemplate>   </table>   </FooterTemplate></asp:Repeater&g

dynamically created button control click event not firing first time?

HI im creating a button control in page int and im assing a click event for the button control. here the click event is not firing for the first time.can anyone help me with this? here is my code. Button btn = new Button(); btn.ID = "btn"; btn.Click += new EventHandler(btn_Click); Panel1.Controls.Add(btn); Panel1.Controls.Add(new LiteralControl(""));

Dynamically add user control with events


I'm trying to make web form with two placeholders. Firs holder contains user control witch has list of buttons, each button opens different user control to second placeholder.

I get it to show user control in second placeholder but i can't get dynamically created user controls to fire events.

So how i can dynamically create working user control with button click?

Here is how i create those controls:

 Dim toiminot As Control = LoadControl("~/kontrollit/" & field.Value)

"field" is hidden field containing filename of user control to be created.

All help is appreciated!

Dynamically Generate No of Control(like Label) depend upon database no of item


I have a requirment like 

i required a dynamically generated Control (like Label) depend upon Database no of item


  If i fetch Database text (like Name) fieldd 3 time than i am intrested to generate  label 3 time

for (int i=0;i<table.row.count;i++)


label label[i]=table.row[i][0].Tostring();


How can do the above because label[i] is not allowed

Khurram Shahzad

SSRS 2008: Multiple Sub-Reports with conditional visibility in one List control


MainReport: a List containing two Sub-Reports. The data of the List only has two rows. Set the visibility of the sub-report based on the data.

SubReport1: a textbox showing "Sub Report 1"

SubReport2: a textbox showing "Sub Report 2"

I expect to see SubReport1 in Page 1 and SubReport2 in Page 2.

But I only see SubReport1 in Page 1 and Page 2 is a blank page.

These reports work in SSRS 2005, but not in SSRS 2008.



Report Definition:



<?xml version="1.0" encoding="utf-8"?>
<Report xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner

Dynamically Centering a Windows Forms Label Control

I'm working on an athletic workout journal application that will include an Interval / Countdown Timer. I plan to build several versions of this application in different technologies (WPF, Web, Phone) but I'm building the first version in Windows Forms. I want the user to be able to dynamically set the size of the "Stopwatch" display font, then resize the form and have the text re-center in the form, taking into consideration the new font size. Stuff like this is easy in HTML, but not so much in Windows Forms. Though I'm still in the early stages I thought I'd share the bit of math that I've come up with and invite any suggestions you might have. Code Snippet using System.Text; using System.Windows.Forms; namespace WorkOutTimer { public partial...(read more)

Dynamically adding steps to wizard control.



I have following table in MSSQL server:

Table: Categories
Columns: CategoryID, CategoryName

I want to dynamically add steps in a wizard control same as all CategoryNames from the table.

Could anyone please help me with this? i've been struggeling with this for days without luck. I'm very new to ASP.NET :-(

Thanks a bundle.

Dynamically adding a javascript control to a row.


Hi all,

I have an old classic asp page that uses a 3rd party javascript calendar control. On that page I dynamically build up controls on a click of a button like so:

function AddContractorRow()
	with (frmMain)
		var objRow = document.all.Table1.insertRow(document.all.Table1.rows.length - 2);

		objRow.style.cursor = "hand";
		objRow.id = "row";

		var objCell = objRow.insertCell();
		objCell.innerHTML = "<input class='mnwInput200' type='text' id='txtTest1' name='txtTest1' value='some val' readonly>";

		var objCell = objRow.insertCell();
		objCell.innerHTML = "<input class='mnwInput200' type='text' id='txtTest2' name='txtTest2' value='some val' readonly>";
		objCell = "";
		objRow = ""


Basically I want to also add this JS control in another cell on the end. Normally to add this control to the page you would just declare it like so:

var calInServiceDate = new ctlSpiffyCalendarBox("calInServiceDate", "frmMain", "datInServiceDate","btnInServiceDate","<%=Date()%>");


Then the markup is just:

[Custom control] Dynamically evaluated properties?


There's a control with propertygrid-alike UI, accepting IDictionary with a known keys set (let it be the SqlConnectionStringBuilder for example. Actually, it is a custom class).

I do not wish to specify key values in template bindings (e.g. Text = "{Binding SourceProp[keyName], RelativeSource={RelativeSource TemplatedParent}}"), so I've added set of protected properties and bind them to the SourceProp property

    public CustomControl()
        new Binding("SourceProp[keyName]")
          Mode = BindingMode.TwoWay,
          Source = this

add dynamically fileupload control


Hi Everyone,

               I have a requirement where i need to add fileupload controls dinamically when Add button is clicked.  In my form i have one Add button and one Save button.

Each time ADD button is clicked one fileupload control must be added to form and i succeded in getting this.

Here is the code

   static int i;
    FileUpload fuPic;
    protected void Page_Load(object sender, EventArgs e)
        if (Session["pnl"] != null)
            Panel pnlfinal = (Panel)Session["pnl"];


protected void btnAdd_Click(object sender, EventArgs e)
        if (i <= 4)
            i = i + 1;

Grab the clientid of a dynamically added control


Hi all,

I add CompareValidators dynamically in my code behind. I need to access these controls within javascript to see if they are active or not. Whats the best way to do this?

The button that calls this javascript is also added dynamically. I dont know how many validators I add and they are added via a loop. I add the name to a string which I pass into my JS function, so within JS I have access to all validators added. Heres my code behind which creates the validators:

CompareValidator CV = new CompareValidator();
CV.ID = "CV" + parameter.Name;
CV.Type = ValidationDataType.Date;
CV.Operator = ValidationCompareOperator.DataTypeCheck;
CV.ErrorMessage = "* Invalid date";
CV.Display = ValidatorDisplay.Dynamic;
CV.ControlToValidate = parameter.Name;
CV.ValidationGroup = "valGroup1";
CV.Style["font"] = "Arial";
CV.Style["color"] = "Red";
CV.Style["font-size"] = "10px";


if (validators != "")
validators += ":" + CV.ClientID;
validators = CV.UniqueID;


I then add my button passing in 'validators' string:

HtmlInputButton btn = new HtmlInputButton();
btn.Value = "Run Report";
btn.ID = "Ru
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