Thursday, August 20, 2009

Page_LoadComplete

I have a page with a user control that has a dropdownlist for date. When the user control loads for the first time, I populate the year options using one of our toolbox methods. When the webform (the user control's host) loads for the first time, I also look in a database to see if there is a date stored that I should use to populate the date field. However, this latter thing was failing on the year field. Eventually I determined it is because the code to load the date from a database was running before the year field had any options - before the user control was fully loaded in other words.

I found these 2 articles that discuss the order of the page lifecycle, and list the lifecycle events:

ASP.NET Page Life Cycle Overview

Page Events in ASP.Net 2.0

I decided to use the LoadComplete() event, which also lets you test for PostBack, which I needed since I only wanted the databinding for the date to happen on first page load.

Just thought I'd mention this in case anyone else ever runs into a similar issue, and also to see whether anyone thinks a different event would have been better to hook into, like maybe Pag_PreRender.

Tuesday, August 18, 2009

Ever to find the table where a column is hiding in a giant DB?

I've been doing alot of this lately, being new to the CTSI db and such.

use this syntax, where 'yourcol' is the known column:

Select table_name from information_Schema.columns where column_name='yourCol'

or you can do a "like", like this:

Select table_name from information_Schema.columns where column_name like '%yourCol%'

Monday, August 17, 2009

accessing a control in a repeater's headertemplate or footertemplate

If you are trying to FindControl on the repeater's ItemDataBound or ItemCreated event it's pretty easy. However I needed to access a control from the repeater's PreRender event. This is when I discovered that "Only items bound to the data source are contained in the Items collection. The header, footer, and separator are not included in the collection." (from MSDN).

Therefore I had to use a line like this which apparently works because "all child controls must exist inside the Controls collection" ("In Search of ASP.NET Controls", from odetocode.com)


HtmlTableRow tr = (HtmlTableRow)rptIncomplForms.Controls[0].Controls[0].FindControl("trFoot");

Wednesday, August 12, 2009

adobe BrowserLab

After reading Layla's blog post earlier this week I spoke with a friend and he turned me on to Adobe BrowserLab. BrowserLab is a hosted web service that provides snapshots of your web site in multiple browsers. It is currently in a limited free preview for people to try out from adobe.com. The best part about ABL is that it can be integrated with Adobe Dreamweaver CS4. All you have to do is go to the link below and download two extensions from the site. You will also need to create an adobe account but its free and their really isn't much information required. Plus by creating an account you will get emails about more products like browserland. So try it out!

https://browserlab.adobe.com/index.html#

jk

Monday, August 10, 2009

mutliple IEs - a follow up

Frustrated by the fact that I still was not getting the standalone ie6 to work following the article I mentioned in this post, I did more digging and eventually unearthed this: http://finalbuilds.edskes.net/iecollection.htm Why was this so hard to find? Beats me. But I have installed it and so far it seems to be working. Right now I have IE8 as my 'real' browser and standalones of the rest. Note that the instructions caution you not to have IE as your default browser. As if!!!

It will install 2 different IE6s (actually it will install what you select, from like IE1 on, although IE1 wasn't compatible with my OD nor did I want it.) Turns out that one is the IE6 from XPSP1 and the other is SP2. If I had realized ahead of time I'm not sure I would have bothered with the first one.

Tuesday, July 28, 2009

javascript regex match on parens

Ugh, that was annoying. I needed to modify this line to also look for parens:
var re = new RegExp("^[a-zA-Z\.\'\,\-]*$", "g");

So I added it to the end, like so:
var re = new RegExp("^[a-zA-Z\.\'\,\-\(\)]*$", "g");

Let me add that I had already modified the server sie validation written in C# which looked almost the same, with no problem. But when I ran the page, the js choked and I got this error in the Error Console of my FF web dev toolbar (because I haven't tried Firebug yet...I know, what is wrong with me?)

"invalid range in character class"

What was this odd error? As far as I can tell, js does not like it if the last character before the ] in my RegExp expression is either ( or ). I moved them elsewhere, several elsewheres, just to see, and the error went away.

Ugh.

Monday, July 20, 2009

programatically change gridview row background color


//change bgcolor of gridview row based on data
//in this case the data I am testing is in a templatefield that is hidden
//if the data had been added in the last hour, then I apply a certain css class

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DateTime entryDate = Convert.ToDateTime(((DataRowView)e.Row.DataItem)["DtEnter"]);
DateTime nowDate = DateTime.Now;
TimeSpan ts = nowDate.Subtract(entryDate);

if (ts.TotalMinutes <= 60)
{
e.Row.CssClass = "updatedRow";
}
}
}