Make sure to add the ” runat=’server’ ” in the markup.
myIFrame.Attributes["src"] = "http://www.google.com";
programming notes…
Jun
01
2010
Make sure to add the ” runat=’server’ ” in the markup.
myIFrame.Attributes["src"] = "http://www.google.com";
May
26
2010
Cannot open database “
Login failed for user ‘IIS APPPOOL\DefaultAppPool’.
I got this error when I added an app onto IIS 7 and was trying to hit my local Database. Here is the fix:
1) In IIS7 – Click ‘Application Pools’ (left side)

—
2) On Top Right – Click ‘Set Application Pool defaults’

—
3) Finally, set ‘Process Model > Identity’ to ‘Local System’

Apr
28
2010
SCENARIO:
Created a simple login that checked user name and password against a database and then sent user to the proper page if verified. (also writing a ‘logged in’ session variable)
Within the pages Page_Load event, I check for the proper session variable and if not present send them back to login screen.
Additionally, I added a logout link that wiped the variable and sent them back to login….
THING all appeared to work great… UNTIL I tried to navigate straight to a page AFTER logging out. The page was able to be accessed EVEN though I had logged out AND my Page_Load event was not even getting called.
====
REASON/SOLUTION:
The pages were being cached and therefore did not need to check the Page_Load event which would have caught the fact that the user was not properly logged in…. The solution is to place the following code in your Load event.
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.Now);
** This is not a proper solution for a large solution with a lot of pages but for this purpose I only had one Default page with user controls … if you have many pages you should use the auth ticket option.
Jan
15
2010
This one almost killed me… I have a nested repeater and could not for the life of me figure out how to find the controls in the nested repeater…
I was doing ONE thing wrong… instead of placing the ItemDataBound event declaration in the Parents ItemDataBound event… I had to put it in the ItemCreated event… and that was it. After that I could easily find my controls.
Protected Sub RepeaterPARENT_ItemCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles RepeaterPARENT.ItemCreated If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then Dim repeaterCHILD As Repeater = New Repeater repeaterCHILD = TryCast(e.Item.FindControl("RepeaterCHILD"), Repeater) AddHandler repeaterCHILD.ItemDataBound, AddressOf repeaterCHILD_ItemDataBound End If End Sub Protected Sub repeaterCHILD_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) If e.Item.ItemType = ListItemType.Header Then Qty = 0.0 End If If CType(e.Item.FindControl("HiddenQuantity"), HiddenField) IsNot Nothing Then Dim HiddenQuantity As HiddenField = CType(e.Item.FindControl("HiddenQuantity"), HiddenField) Qty += CDbl(HiddenQuantity.Value) End If If CType(e.Item.FindControl("LabelQTYSubtotal"), Label) IsNot Nothing Then Dim LabelNew As Label = New Label LabelNew = CType(e.Item.FindControl("LabelQTYSubtotal"), Label) LabelNew.Text = Qty.ToString End If End Sub
Jul
27
2009
This structure keeps coming up :
dsSchools = mydata 'Create table to bind to dataGrid Dim dt As New DataTable Dim nameCol, activeCol As New DataColumn dt.Columns.Add(nameCol) dt.Columns.Add(activeCol) Dim dRow As DataRow = dt.NewRow For Each dr As DataRow In dsSchools.Tables(0).Rows If Not dr("title") Is DBNull.Value Then dRow(nameCol) = dr("title") If Not dr("IsActive") Is DBNull.Value Then dRow(activeCol) = dr("isActive").ToString dt.Rows.Add(dRow) Next
Jul
17
2009
For Each loops is a read-only loop! In other words, you cannot mutate the reference you are referring to.
A For Next loop allows mutation, plus I like For Next’s because they allow me to determine if I am on the final loop or not…
Examples,
For x as integer = 0 to myStringArray.Count – 1
myStringArray(x) += “add this to end”
if x = myStringArray.Count – 1 then myStringArray(x) += “, and this is the last element!”
Next
cheers!
t
Jul
16
2009
I JUST FOUND THIS INTERESTING, THIS MAY OR MAY NOT BE HELPFUL… BUT I STARTED PLAYING WITH AN ARRAYLIST IN VB AND FOUND OUT THAT YOU CAN HOLD MULTIPLE TYPES INSIDE OF A SINGLE ARRAY.
TAKE A LOOK AT THE CODE BELOW – SEE THAT I STORE A STRING, 2 INTEGERS, AND A BOOLEAN ALL WITHIN THE SAME ARRAYLIST. I THINK THAT’S COOL…BUT I’M A DORK.
EVEN COOLER, YOU WILL SEE THAT THE ARRAYLIST CAN MAKE DECISIONS BASED ON THE TYPE IT IS LOOKING AT… (IS THE BOOLEAN TRUE OR FALSE?, DOES THE ARRAYLIST CONTAIN THIS STRING?, WHAT IS THE RESULT OF ADDING THIS ITEM TO THIS ITEM, AND CONCATENATING A STRING AND AN INT)
I IMAGINE THIS IS PROBABLY A TERRIBLE PRACTICE BECAUSE YOU WOULD HAVE TO KNOW THE TYPE AT EACH ELEMENT, BUT INTERESTING NONE THE LESS.
Dim arrList As New ArrayList
Dim theString As String = "TR"
Dim theInt As Integer = 54
Dim theBool As Boolean = False
Dim theInt2 As Integer = 46
arrList.Add(theString)
arrList.Add(theInt)
arrList.Add(theBool)
arrList.Add(theInt2)
MessageBox.Show(arrList(0))
MessageBox.Show(arrList(1))
MessageBox.Show(arrList(2))
'Now to tests
MessageBox.Show(arrList.Contains("TE")) 'Should be false
MessageBox.Show(arrList.Contains(54)) 'Should be true
MessageBox.Show(arrList.Contains(False)) 'Should be true
MessageBox.Show(arrList(1) + arrList(3))
MessageBox.Show(arrList(0) & arrList(1))
'MessageBox.Show(arrList(0))
'MessageBox.Show(arrList(1))
'MessageBox.Show(arrList(2))CHEERS!
T
Jul
15
2009
I would just like to point out two areas where both C# and VB.Net beat the other one in the usage of arrays.
C# PRO:
You can redefine your array simply in C# by simply reinitializing the array:
//Declare array int[ ] myInts = new int[20]; //Now reinitialize like this myInts = new int[40];
In VB you have to reinitialize with the ReDim keyword
Dim myInts(20) ReDim myInts(40)
Not a big deal but I give the better implementation to C# on this one…however.
===========================================
In VB.Net you can actually reinitialize an array AND MAINTAIN the data within the current array!
This is accomplished by using the ‘Preserve’ keyword. (this is not available in C#)
'Declare array Dim myInts() As Integer = { 1,2,3,4 } 'Resize array and keep the data with the Preserve keyword ReDim Preserve myInts(20)
Jul
06
2009
Here is one cool way to get a string into a dataset:
First build your string so that is correctly formatted XML. For instance:
Dim strXCustInfo As String = "<Root><CusTable><Name>Todd </Name><Address>123 Fourth Street</Address></CusTable>" & _ "<CusTable><Name>Dawn </Name><Address>432 Washington Ave</Address></CusTable></Root>"
Now that we have this, we need to convert the string into a Stringbuilder.
Dim srCustInfo As New StringReader(strXCustInfo )
Now create your dataset and call the .ReadXml method on the dataset to get the above string right into a ready to be stored dataset! WOOT!
Dim ds As New DataSet ds.ReadXml(srCustInfo)
Hope this helps someone!
Jul
02
2009
This is very simple but something I can never remember how to do!
'So we have a TABLE of data and want to put a title and value into a dropdown on our page. For row As Integer = 0 To DT.Rows.Count - 1 If Not DT.Rows(row).Item("Title") Is DBNull.Value And Not DT.Rows(row).Item("ID") Is DBNull.Value Then Dim a As New ListItem a.Value = districtDT.Rows(row).Item("Title") a.Text = districtDT.Rows(row2).Item("ID") myDropDown.Items.Add(a) End If Next
There you go!
t