Wednesday, November 4, 2009

Publish Failed - No Errors?

Hi All

I have run a across this a few times in the past and it drove me crazy:

Ever Build – The build succeeds, then when you Publish, you get “Publish Failed” but you don’t see any errors as to why? (it happens so few and far between – usually it’s a missing file / dll)

I found this on the web…

http://forums.asp.net/p/1248620/2478095.aspx

Try opening your Output Window in VS2005 or 2008 THEN publishing. It will display the errors that are stopping you from Publishing.

GMWEBDEV was full and VS2005 was unable to publish to it but I was not seeing that error in the Error List – It was only displayed in the Output Window.

Wednesday, September 2, 2009

Hi all,
I found something useful for a change and thought I'd share. :) While trying to check the accuracy of a specific origin path of a file to be uploaded to a destination directory from a web page I found that some newer browsers handle this a bit differently. For example, if the user browses to the file C:\Docs\myfile.doc on their machine from a web page, from an input box with type "file", the .value property of the input box in the C# code will return C:\fakepath\myfile.doc in IE8 and some other newer browsers. This MSDN article tells you how to get around that, only it is up to the user to do so by manually changing a security setting in IE8.

Since I can control the browser type and settings of the users for this project it's no big deal. But unless someone can find a way to read the entire file path in IE8, all you can call is the file name via the code. I'm sure this isn't going to be a common occurance, but I thought it was worth noting.

Another example:
I have this code...

if (File1.Value != @"C:\KneeOA\Back_End\KneeOA_Back_End.mdb")

...which is checking the path of the file to be uploaded because it has to be very specific for this project. IE8 only returns "KneeOA_Back_End.mdb" for "File1.Value" which is not really helpful. IE7 and earlier do return the whole path and therefore can check it for accuracy without having to change an IE security setting.

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";
}
}
}

Thursday, July 9, 2009

dynamically hiding rows in a repeater

I recently needed to hide a row in a repeater if it had no data. I feel like I had done this before but I could not remember how. After a lot of reading and experimenting, I figured out that it was really pretty easy to do. (Note that I read a couple of ways that I think were not the way to go, so I'll mention them here: one person ad made a hidden footer row, and used that to test for missing data and determine whether to hide a row. Another person used FindControl to see if the field was empty, and then set the CSS dynamically to hide the row if needed.)


1 protected void rptGrants_ItemDataBound(object sender, RepeaterItemEventArgs e)
2 {
3 DataRowView drv = (DataRowView)e.Item.DataItem;
4 if (drv["fieldName"].ToString() == "")
5 {
6 HtmlTableRow tRow = (HtmlTableRow)e.Item.FindControl("tableRowID");
7 tRow.Visible = false;
8 }
9 }


Again, I was using a repeater, and called a class method to bind the data to a DataTable. In the first line, we're accessing the data that is currently being bound to the repeater control - note that this event (ItemDataBound) is fired as the repeater iterates and binds to each row of your data. The item the repeater binds to is a DataRowView - your row of data has been turned into this DataRowView to give it more properties which enable the Repeater to do things like sort and filter, etc.

So, in line 2, I examine the specific column I'm interested in to see if there's anything there to display. Since this column is of varchar type, I check if it's empty.

Next I need to use the FindControl method to call the table row I want to hide, if the field I'm looking at is indeed empty.

That's all there was to it! Note that if my repeater had anything other than ItemTemplates or AlternateItemTemplates in it, I would have tested for the template type before the rest of my code.

References:
http://idunno.org/archive/2004/10/30/145.aspx
http://www.velocityreviews.com/forums/showpost.php?p=526696&postcount=4

More on DataRowView:
http://books.google.com/books?id=tKytuTyw3boC&pg=PA461&dq=datarowview&ei=d9pVStW2OIWQNvL5zPsJ

Monday, June 29, 2009

new toolbox function

Probably of more interest than my last post: I added a function to the toolbox that will take a datatable, and email it as an excel attachment. Exciting!

new validation function: isValidPassword

I added a new function to the toolbox to validate a password field specifically, assuming that the password may have upper/lower case letters, numbers, or any one of a few punctuations (see actual code for reference). I'm posting about this because I added it to the ValidateAlpha class.As I did so I thought that really the Alpha is not the most accurate name as there are functions in there that validate strings beyond just alpha. However it's kind of late to rename it since it's widely called.

Just be aware that these kinds of functions may already exist before troubling yourself writing a new one!

Wednesday, June 24, 2009

running ie 6, 7 and 8

just read this - for the curious:

http://blog.case.edu/jeremy.smith/2008/03/07/ie_6_7_and_8_running_on_same_machine

I'll be trying it fairly soon, because I still like to test in 6, but I guess some goobers are using 8 now!

Thursday, April 30, 2009

referring to radio button in DOM fashion

so for ages now we've been calling a radio button using the non-DOM method of document.formname.radiobuttonname. But yay! Recently Jason & I figured out the DOM method for doing it: document.getElementsByName("radiobuttonname")[index]

Remember these are 0 indexed.

So feel free to change your javascript to it's entirely using the DOM way to reference page elements. Exciting stuff!

Monday, March 9, 2009

share a user control across projects in a solution

I used this article to figure this out. Here is my summary of the article, for what I did for a recent solution.

You can keep the user controls to the project you initially created them in, but use then in other projects of the same solution by adding a pre-build event to the project where you want to also use the controls. You can add such an event by going to the Properties of the project (right click on the project in solution explorer) where you want to add the controls, and go to the Build Events tab. You type a command to copy the controls from the project they were created in, to the project you want them to be used in. Then, before running a build on this project, if you have directed the control to be copied into a directory, you do need to make sure that directory exists. For DOM at this point, I created a folder called UserControls into whatever project I was adding the controls to. Finally, after you run the build, make sure you include the folder and/or the controls that were just copied over in the project they were just copied into.