.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

Code from the ground up, or use just populate placed controls?

Posted By:      Posted Date: September 21, 2010    Points: 0   Category :ASP.Net

As an Ex ASP Classic moving to ASP.net (VB) i find the following situation, and i'm looking for some direction in terms of best practice.  

As i'm sure we all do when we start, i easily get lost in all the controls and clever wizard driven development features.  however, my best .net work so far has been without any drag/dropped controls, but rather programatically creating whatever controls/connections/dataobjects i need, populating, acting on and disposing of thereafter.

There was a post i saw (somewhere) which referred to the sqldatasource and gridview controls and their consorts as "training wheels" controls and i identified with that statement straight away.

Now here's the question: is this a question of arbitrary "preference" or is this something that has larger implications later on?   I realize that it's a kind of up-in-the-air question, but I don't want to be more specific than that in my question because I want to see what others think about this.

View Complete Post

More Related Resource Links

populate report viewer by code


Hi all

I have a button "Show Report" to show some data from table

what I should write under this button to populate the reports ?

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>)


Hey guys

I came across this bug using while trying to implement a sitemap

Line 147:						Panel panel = new Panel();
Line 148:						panel.Controls.Add(_viewState);
Line 149:						Page.Form.Controls.Add(panel);
Line 150:						string script = "document.getElementById('" + _viewState.ClientID + "').value = GetViewState__AspNetTreeView('" + Extender.MakeChildId("UL") + "');";
Line 151:						Page.ClientScript.RegisterOnSubmitStatement(typeof(TreeViewAdapter), _viewState.ClientID, script);

[HttpException (0x80004005): The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).]
   System.Web.UI.ControlCollection.Add(Control child) +8696951
   CSSFriendly.TreeViewAdapter.SaveAdapterViewState() in E:\wwwroot\ThirdParty\CSSFriendly\CSSFriendly_24242\CSSFriendly\TreeViewAdapter.cs:149
   System.Web.UI.Control.SaveViewStateRecursive(ViewStateMode inheritedMode) +8901848
   System.Web.UI.Control.SaveViewStateRecursive(ViewStateMode inheritedMode) +148
   System.Web.UI.Control.SaveViewStateRecursive(ViewStateMode inheritedMode) +148
   System.Web.UI.Control.SaveViewStateRecursive(ViewStateMode inheritedMode) +148

Toolbox: Microsoft Chart Controls, Visual Studio Automatic Code Snippets, And More


In this installment we look at the Microsoft Chart Controls; Snippet Designer, a free, add-in for Visual Studio 2008 for creating and editing Code Snippets; refactoring SQL applications; and this month's favorite blog.

Scott Mitchell

MSDN Magazine April 2009

Wicked Code: Craft Custom Controls for Silverlight 2


If you're unfamiliar with Windows Presentation Foundation (WPF), building that first Silverlight custom control can be a daunting experience. This article walks through the process.

Jeff Prosise

MSDN Magazine August 2008

Open browser window + populate from code behind

Hi,I have a variable, which contains a whole web page. Is there a way to open a new browser window and set the contents of this variable as the page? I don't mind if it's javascript, but it has to be able to hold a bit of data if this is the case.Thanks!

Need some help with the AnimationExtender controls in C# code behind only


Hi all,

I'm developing a custom webpart for MS Project 2007 (sharepoint 2007 engine). I would like to have exactly the same result as this demonstration -> http://www.asp.net/ajax/ajaxcontroltoolkit/Samples/Animation/Animation.aspx but the window is displaying above my button and not correctly. I need your help, please.

Here is my code:

Literal div1 = new Literal();

            div1.Text = "";
            div1.Text += "<div id='flyout' style='display: none; overflow: hidden; z-index: 2; background-color: #FFFFFF; border: solid 1px #D0D0D0;'></div>";

            div1.Text += "<div id='info' style='display: block; width: 250px; z-index: 2; opacity: 0; filter: progid:DXImageTransform.Microsoft.Alpha(opacity=0); font-size: 12px; border: solid 1px #CCCCCC; background-color: #FFFFFF; padding: 5px;'>";
            div1.Text += "    <div id='btnCloseParent' style='float: right; opacity: 0; filter: progid:DXImageTransform.Microsoft.Alpha(opacity=0);'>X";
            div1.Text += "        <a onclick='return false;' id='btnClose' title='Close' href='#' style='background-color: #FF5B00; color: #000000; text-align: center; font-weight: bold; text-decoration: non

Do you have to instantiate all objects/controls on the webform in the behind code page?


Hello everyone.

I have a MSchart control in my webform called Chart1 which is part of the namespace:  System.Web.UI.DataVisualization.Charting.Chart 

I am developing a multi-user (simultaneous connection) to a webform that manipulates controls and displays data on the graph.  Anyhow, I am immediately calling the Chart by using the reference: Chart1.Series.etc.etc.  or Chart1.Series.Addpoints. etc.etc.

My main question is, do I need to do a System.Web.UI.DataVisualization.Charting.Chart Chart1 = new System.Web.UI.DataVisualization.Charting.Chart();  inside  my page_load so that each user gets their own object instance of the Chart1 object?

So that way, if a second user changes the XY data, while the first user just changes the axis, then when the first user re-loads the updated graph, he does not get wrong data (overwritten) by the second user during a cross-session usage?

So must I create an object instance for all users for the MSchart control?


On GridView Click, populate other controls with column values


Hello team,

I have 5 controls on the page - textbox, radiobutton, listbox, checkbox, and any other one more. And i have a grid. The grid has 5 corresponding columns. I have to make the grid row clickable, and on the click, i have to populate my 5 controls with each of the corresponding grid column values.

Please let me know how can i make it. I know that i can make the grid clickable, by setting the e.row.attribute.add("OnClick", "javascript:return passValues();");. In this case, all the value passing will happen in javaScript. Is this the correct way? I have yet to try implementing this, not sure if there will be any issues.

Before that wanted to know if there is any other approach to achieve this. Please help!

Odd issue with createuserwizard--can't see controls I add to template in code behind in .net 4.0


I was able to customize the createuserwizard in .net 3.5 with no problems.  I could add controls like the dropdownlist for city and state.  In the code behind, I was able to reference these controls by name, such as ddlstate.  However, I'm creating a new site from the ground up in .net 4.0 and was trying to edit the website that visual web developer 2010 creates when you create a new web site.  I went to the register.aspx page and added the city and state dropdowns.  In the code behind, I can't reference them as ddlstate anymore.  I even tried setting the clientidmode to static at the page level since I know the control names get mangled but that didn't help either.  However, the project builds fine as long as I don't attempt to reference the dropdownlist by name in the code behind. 

I'm also using jquery that I pulled from a working .net 3.5 site I had that gets errors when trying to reference the dropdownlist by name in .net 4.0.  The error says "ddlstate" is not a member of "asp.account_register_aspx".  The dropdownlist is set to runat server so I'm really confused why both my jquery and code behind can't seem to see the control in the createuserwizard control.  If I move the dropdownlist outside of the createuserwizard, it can see it and use it just fine.  A

AJAX DropDownList won't populate.. error500.. code is working though.


Here's what I have.  I was able to debug and traverse through the webservice and return teh array back into the first call method of: return new CarsService()..  But back in the page_load method, I can't get it to update and show up in the page.  what am I doing wrong?!?!


<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
                    <cc1:CascadingDropDown ID="CascadingDropDown1" runat="server" TargetControlID="DropDownList1"
                     Category="Make" PromptText="Please select a make" LoadingText="[Loading makes...]"  

how will take the html controls value from source code to code behind of asp.net page


i created a calendar user control in asp.net+c#.it have two html text boxes and one img button.but i dont know ,how will take
the values to code behind of asp.net from html text boxes values at runtime on the onclick of html img button.....Any ideas????.

This is my main code


      <div>View from:</div>
         <div>  <input type="text" name="showdia" id="showdia" size="9" value="10/04/2010"><input onclick="return showCalendar('showdia', 'mm/dd/yyyy');"  type="image" src="images/cal.gif" align="absmiddle" name="reset" style="cursor:pointer"></div> 
         <div>  <input type="text" name="showdiafin" id="showdiafin" size="9" value="10/04/2010"><input onclick="return showCalendar('showdiafin', 'mm/dd/yyyy');" type="image" src="images/cal.gif" name="reset" style="cursor:pointer" align="absmiddle"></div>
    <div align="center" style="padding:3px;"> <img src="images/language/english/view.g

code SQL to populate gridview with multiple random list box selections, How to


I could use some help in coding a query.

I have a list box that allows for multiple selections (holding down the control key) the selection quantity is basically unlimited, but realistically should never be more than 50 to 100 items from the listing of about 3000 items.

I need to collect the list of selected items from the drop down list and retrieve each of their full records from the item master and populate a gridview.

Any help would be greatly appreciated.


Thanks again,



Code behind file controls not defined/recognized when using WSPbuilder in Visual Studio 08


I am in the process of adding my custom aspx pages to the LAYOUTS folder(a folder I created) in a WSPbuilder solution in VS08. The problem I am having is when I build the solution it fails because the controls(Load, Textboxes, dropdown lists,etc) in the code behind file for the custom aspx pages say they are not defined. They all have a blue squiggly line and I get over 100 errors. Does anyone know what to do to get the WSP to recognize the code behind pages. Is there a setting or something I am missing.

is there a way to populate an infopath form with just plain code?


I'm what you consider a n00b - i've only done some basic stuff with sharepoint - debugged some stuff, but now i need to find if something's possible.


Here is what i have:
1) I have an infopath form that is hosted on our sharepoint site
2) I have a workflow that routes emails and all that fun stuff and allows end user to "complete" a workflow.

Currently users start workflows in their browsers.

Here is what i need to do:

I have created a webservice to which i will have my users send me information (same information as the infopath form collects today)

but with the twist that i will have some sort of a web app that will PUSH this information and "fill out" the infopath form thus starting the workflow process - this all to be done in the background.

My infopath forms information is stored as .xml files within sharepoint - and i'm not sure how i can create these without physically opening up the form in a browser - instead just send information to the form and POOF have it start the logic of the workflow.

Is this possible? 
Please point me in the right direction 

User Controls : load and access properties from code behind



I created a User Control :

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="UCSousMenuPrincipal.ascx.cs"
    Inherits="view_usercontrols_UCSousMenuPrincipal" %>
<asp:DataList ID="dataListSousMenuPrincipal" runat="server" RepeatDirection="Horizontal" >
        <asp:HyperLink ID="HyperLink1" runat="server"><%# Container.DataItem %></asp:HyperLink>

to which I added a property, so I can bind the DataList :

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;

public partial class view_usercontrols_UCSousMenuPrincipal : System.Web.UI.UserControl
    //Private Member    
    private object dataSource = null;
    protected void Page_Load(object sender, EventArgs e)

populate dropdown with code



i have 2 dropdown fields the first drop dropdown ownly holds 2 items : "technical questions","broken stuff".

i have made 2 data connection with the right lists.

the second drop down i want to populate, depending on the selected value.


i was thinking, i have already the data connections when i go to the code on the change event.

i can work with this data connection and populate the dropdown.

but i'm dooing something worng can anybody give some suggestions?



SQL code to populate gridview with multiple random list box selections


I could use some help in coding a query.

I have a list box that allows for multiple selections (holding down the control key) the selection quantity is basically unlimited, but realistically should never be more than 50 to 100 items from the listing of about 3000 items.

I could really use some help building the SQL statement to select the choosen record data. I think I have the selection list worked out by populating an array but I am not clear on how to build the SQL query.

Any help would be greatly appreciated.


Thanks again

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