Dec 18 2007

Scary Visual Studio 2008 Guy

I was installing Visual Studio 2008, when all of a sudden I saw him. Wait, let me back up. You know how when you install an app, and you are shown all those lame screens of people smiling at work and a little blurb about how awesome the app is that your installing flip by. Well, whoever this guy is takes the cake. It’s just not natural…

Picture 1.jpg

Dec 18 2007

ASP.NET Tracing

What I learned today:

1. .net tracing is freaking awesome. Talk about being able to pinpoint your problems! Sheesh! I wish I had this a looooong time ago.

2. My db server needs more ram. I guess 512 isn’t enough ;)

All this time, I figured it was my code, or possibly something with the web server that was causing my site (BodyMod.org) to run so slow. Nope… DB server. I ran some trace events tight around all the DB calls, and low and behold, that’s where all the time was coming from. Up to 15+ seconds for a DB call!

So I head on over to my db server to check out whats up. I pull up my task manager and see cpu at 60-70% ( not great, but not bad ), and my ram usage at about 615 out of 1024. Not bad either. So wtf?

Oops… only 512 of that is physical. the other 100 is virtual. Crap.

So, I sent an IM to my server guy (it’s 5am, so I doubt he’s up) that I wanted to buy some more ram. I figure with prices the way they are, I’ll bump it up to 2gb =)

Better be the miracle fix I was looking for.

So to all you bmod members out there, hold tight, it’s about to get crazy fast! (probably not, but I dream big =)


Oct 30 2007

Unable to cast object of type ‘x’ to type ‘x’.

Talk about an ambiguous error…

I just got this is .NET for what appears to be no reason at all. Turns out that this is an issue with .NET when it doesn’t fully compile the page. The only way that I’ve found to resolve this issue is to delete the temp files under:

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files

<rant>
.net is cool and all, but seriously. I’ve encountered a lot of ‘bugs’ while working with it. WTF? Classic ASP never any any issues like this in the 7+ years that I’ve been using it…. ARG!
</rant>


Oct 23 2007

Messed up .NET error

Last night, everything was working fine. Then I wake up this morning to find out that this error is on all of my aspx pages were throwing it:

Server Error in ‘/’ Application.
Could not load file or assembly ‘System.Web.Services, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’ or one of its dependencies. The handle is invalid. (Exception from HRESULT: 0×80070006 (E_HANDLE))
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IO.FileLoadException: Could not load file or assembly ‘System.Web.Services, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’ or one of its dependencies. The handle is invalid. (Exception from HRESULT: 0×80070006 (E_HANDLE))

I stopped IIS and deleted the temp .net files and started IIS back up. Worked for me. Here’s the path to the temp directory:

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\

You may want to also check to make sure that the domain your .net files are in are set to 2.0 and not 1.1.


Oct 22 2007

Get Image Dimensions with .NET

I wanted to get the dimensions of an image that I was going to load in a popup so that I would know how big to make the popup. I also didn’t want to open my aspjpeg component as I’m trying to keep it all in .NET

Here’s what I came up with:

Dim strPhoto As String = “/images/newPhoto.jpg”

Dim workingImage As System.Drawing.Image = System.Drawing.Image.FromFile(Server.MapPath(strPhoto))

Dim intWidth As Integer = CInt(workingImage.PhysicalDimension.Width)

Dim intHeight As Integer = CInt(workingImage.PhysicalDimension.Height)

this will put the width and height into variables that I can play around with.


Oct 20 2007

Getting data from master pages in child pages

Here’s an example that I used to dynamically change the meta tags in my page:

Master Page: VB:

Public Property MetaDescription() As String
Get
Return Page.Header.Attributes.Item(“Description.Content”)
End Get
Set(ByVal value As String)
Dim Description As New HtmlMeta
Description.Name = “description”
Description.Content = value
Page.Header.Controls.Add(Description)
End Set
End Property

Public Property MetaKeywords() As String
Get
Return Page.Header.Attributes.Item(“Keywords.Content”)
End Get
Set(ByVal value As String)
Dim Keywords As New HtmlMeta
Keywords.Name = “keywords”
Keywords.Content = value
Page.Header.Controls.Add(Keywords)
End Set
End Property

Then set / retrieve the data from the child page:

Child: VB:

Master.MetaDescription = “”
Master.MetaKeywords = “”

You also want to make sure that you put this bit of code in the child page aspx file:

<%@ MasterType VirtualPath=”~/Global.master” %>

Oct 17 2007

Concat String with itself in .NET

This is prolly a really n00b thing of me, but I couldn’t figure out a better way to concat a string with itself, so I reverted to doing this:

Dim strMyString As String = “”

strMyString = “Hello”
strMyString = strMyString & ” world”

myLabel.Text = strMyString

Well, here’s the easier way:

Dim strMyString As New StringBuilder

strMyString.Append(“Hello”)
strMyString.Append(” world”)

myLabel.Text = strMyString.ToString


Oct 17 2007

Paging in .NET without a DataGrid

Again with the paging…

Well, I need it. I’ve spent waaaay to long trying to redesign the mod listing pages and this is what I’ve come up with that seems to work:

ASP Design Code:
<div id=”Content”>
<asp:DataList id=”theDataList” RepeatLayout=”Flow” runat=”server”>
<ItemTemplate>
<div class=”Item”>
<%#BuildItem(DataBinder.Eval(Container.DataItem, “fld1″), DataBinder.Eval(Container.DataItem, “fld2″), Container.ItemIndex)%>
</div>
<%#LineWrap(Container.ItemIndex)%>
</ItemTemplate>
</asp:DataList>
</div>
&gtscript language=”javascript” type=”text/javascript”>stripOutBR(‘Content’);</script>
VB:
Dim strConn As String = ConfigurationManager.ConnectionStrings(“Database”).ConnectionString
Dim objConn As New System.Data.SqlClient.SqlConnection(strConn)
Dim objCommand As New System.Data.SqlClient.SqlCommand
Dim dsTemp As System.Data.DataSet = New System.Data.DataSet
Dim strSQL As String = “”

objCommand.Connection = objConn

strSQL = “SELECT * FROM table”

Dim objAdapter As New System.Data.SqlClient.SqlDataAdapter(strSQL, objConn)

objAdapter.Fill(dsTemp, “table”)

objConn.Close()
objAdapter.Dispose()
objConn.Dispose()

Dim objDps As PagedDataSource = New PagedDataSource
objDps.DataSource = dsTemp.Tables(0).DefaultView
objDps.AllowPaging = True
objDps.PageSize = 15 ‘ Amount of records to show on each page

theDataList.DataSource = objDps
theDataList.DataBind()

Public Function BuildItem(ByVal fld1 As String, ByVal fld2 As String, ByVal intCount As Integer) As String

Format the data to be displayed the way I want

End Function

‘ This function is used to throw in a div with style=”clear:both”
‘ to make a new line every 5th object
Public Function LineWrap(ByVal intLineNumber As Integer) As String
Dim strSpacer As String = “”
If intLineNumber = 4 Or intLineNumber = 9 Or intLineNumber = 14 Then
strSpacer = “<div class=”"spacer”"> </div>”
End If
Return strSpacer
End Function

Javascript:
/* this script is to clear out the tags the DataList throws in.
IE 6 doesn’t like them. Just make sure you call it AFTER
the datalist is written out. */

function stripOutBR(theID){document.getElementById(theID).innerHTML = document.getElementById(theID).innerHTML.replace(/<\/span><br><span>/gi,”);}

Then using the various methods of the objDps object (the PagedDataSource) you can set the current page, list out how many items there are, how many pages, etc. Just mess around with it. I’m not saying this is perfect or correct, as I’m still learning. But this is how I do it and it seems to work.


Oct 17 2007

Getting Rid of Tables in a DataList (.NET)

I’ve been working on Paging in .net and damn… I never thought it’d be this difficult. I mean, in Classic ASP, paging is pretty simple with ADO. But This whole DataGrid, DataList thing is sending me for a loop.

Anywho, I finally got a DataList to spit out the data that I needed, but it used <table> structure to do so. This is probably fine for most people, but I’m trying to design BodyMod.org to be a CSS driven site (Div’s not Tables). So… this was bad. If you’re like me, here’s what you do. Just add the tag RepeatLayout=”Flow” to your DataList object like so:

<asp:DataList id=”theDataList” RepeatLayout=”Flow” runat=”server”>

And whammo… no more table, tr, td outputs =)