Techie Talks

Thursday, September 15, 2005

ASP.NET Dynamic control loading, placement and styling

In order to load a system control such as TextBox, use:
TextBox tx = new TextBox();

This fails for some controls such as CheckBox. In such cases, add a panel, say "TestPanel" and add the control to the testpanel.

CheckBox cb = new CheckBox();

In order to load a user control say MyUserControl.ascx, use
MyUserControl mucl = LoadControl("MyUserControl.ascx") as MyUserControl;

This way, the properties and methods exposed by MyUserControl can be accessed. However, the individual child controls cannot be accessed directly. They may have to be set as property values by the control's code behind.

Placing and editing style of the control
Once a control is created, before loading it to a the page (or panel), their position, style etc can be set using the control object's Style attribute using:

CheckBox cb = new CheckBox();
cb.Style["display"] = "block"; // The block style of display positions the control on a new block/line

Monday, September 12, 2005

VS 2005 Beta 2 - Templates vanish from "Add new item"

In the Visual Studio 2005 Beta 2, suddenly today, when I try to add a new file to the project using "Right click on project" ->Add New Item, the resulting dialog was empty! i.e., the templates were empty.

1) Open up a command prompt

2) Go to folder having the executable for the Visual Studio 2005 Beta 2 IDE - devenv.exe, which in my setup was C:\Program Files\Microsoft Visual Studio 8\Common7\IDE>

3) Run devenv.exe /resetuserdata

The process did not bring up any window. But, in my taskmanager, I could see the process running. Finally, it unloaded from taskmanager. At this point, I ran the IDE normally from Start menu and everything looks fine now.

Thursday, September 08, 2005


For a quick note on INNER/OUTER/LEFT/RIGHT JOIN available in SQL Server (I have no idea about its availability on other databases), see

Scheduler issue

A goodie that I have been looking for quite sometime is a nice little scheduler that can be updated online, exported offline and sync-ed when I go online again. If you have a server running Exchange Server (and you have an account in that :P), its a piece of cake. But, unfortunately, thats not the situation at hand with me.

My office-mate suggested getting a BlackBerry 7100g cellfone which has a nice scheduler. Great idea, yet I am a fan of freebies or at least semi-bies, not ~200$-bie!

So, here is a possible solution I came up with. I have Microsoft Outlook 2003 running at both my office and home. I am planning to make use of its export/import feature, use email as the exchange medium (or flash drive!) to move the schedule to and from home and office as .csv files. I guess I will be doing this for the Tasks and Calendar folders.

Future Work
1) I need to create a small tool that does this sync-ing automatically, probably using a new Office addin for Visual Studio 2005

2) Create a small tool that can read/write entries on the .csv files so that I can use it on comps where Outlook is not available.

3) Have an online read/update site on this .csv file. Questions (other than how?): Where? (Read: Server)

Dual monitors!!

Before I forget, my company got me a video card yesterday that supports dual monitors. I added an LCD monitor to my existing CRT. Now I have more "work space"!!! Thank you GSW!

Dynamic Crystal Report Generation - Day 2

Well, it has been some horrible 24 hours since I started looking for a solution to totally dynamic crystal report generation. Even the omni-potent Google failed to help. All I found was frantic cries by people (some guy was even ready to buy a beer) to find a similar solution. I think its not a good idea to spend more time doing any more research on this, at least for the time being.

Solution (for now)
I, finally, am planning to create a report at design time with all possible fields pulled into it and then use the remove/edit method mentioned in the prev post to cull out unwanted columns. Also, to use a filter on what records are to be pulled, the following comes in handy:

string selectionFormula = "Mid({employee.emp_id}, 1, 1) = 'A'";
testReport.DataDefinition.RecordSelectionFormula = selectionFormula;

The above code snippet works kinda like a SQL select statement. It pulls only those records with employee ID's beginning with an A. I need to do more study on other filters. But thats only second in my list. My current to-do list is as follows:

1) Generate report with dynamic columns
2) Be able to position the seen columns properly when central columns vanish.
3) Be able to populate only required records.

Future Work
To be able to add columns dynamically (the issue that I am going thumbs-down for now). When is this "future"? No idea. "As time permits", to be politically correct!

Wednesday, September 07, 2005

Dynamic Crystal Report Generation

Most of my efforts this week has been dedicated to generate crystal reports dynamically or "codically". Though I have not been 100% successful in this endeavor, I saw a few pieces of gold here and there. The following tests have been performed using Visual Studio Beta 2005 and whatever version of Crystal Reports it came with!

Removing/Editing an existing object from the report
In order to remove an existsing report object from a report (testReport), the following code can be used as an example:

testReport.ReportDefinition.Sections["Section3"].Height = 600;
testReport.ReportDefinition.Sections["Section3"].ReportObjects[0].ObjectFormat.EnableSuppress = true;
//The report object as well as section can be addressed using the integer subscript (as done in ReportObjects[0]) or its name (as done in Sections["Section3"])

Friday, September 02, 2005

ASP.NET: Loading controls only once at runtime - Solved!

The side effect that I mentioned in the previous post has been solved!
Solution: In order to solve the problem under question, from the previous post, of executing a section of Page_Load only when a page is loaded for the first time, the Page.IsPostBack flag is used. This flag tells you whether the reason for the Page loading is to reflect some post back action. Thus, our run-once section can be written inside the Page_Load() method as:

protected void Page_Load(object sender, EventArgs e)
        //Run-once section

The use of static variable mentioned earlier for this purpose is, thus, NOT a good idea to solve this problem!

ASP.NET: Loading controls only once at runtime

Well, if the title isnt too great, the exact problem statement is this:
"I have an aspx page with some controls that need to be populated at runtime. However, they need not be loaded if the page is refreshed. How can this be achieved?"

Which, in other words, mean that certain section of code under the Page_Load() method of the page needs to be executed exactly once. It should not be executed when the page is refreshed (which also happens after a POST event, I guess).

Answer: Declare a static boolean variable inside the class, for example

static bool once = false;

set this flag inside the run-only-once section of Page_Load()

such as
... ...
//Run once section
once = true;

Side-Effect: Doing so, however, would result in the run-once not being exectued until the code is recompiled!! That is, if u run two instances of the same page, the run-once section will get executed only once!! I am still trying to resolve this!!