Web Control Issue
I was playing around with creating a web control you can add to the toolbox. To create this I started with a VB 2005 class library project. I added a reference to the system.web. I added a bitmap to the project and set its build action to embedded resource. I also set the tagprefix for the control. Here is the issue. If I set the namespace in the project properties everything works as expected. If set the namespace the toolbox bitmap and tag prefix do not work .
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Drawing
<Assembly: System.Web.UI.TagPrefix("MyControls", "kens")>
<ToolboxBitmap(GetType(MyWeatherSticker), "Arrow.bmp")> _
<ToolboxData("<{0}:MyWeatherSticker runat='server'></{0}:MyWeatherSticker>")> _
Public Class MyWeatherSticker
Inherits WebControl
Public Sub New()
' your code goes here
End Sub 'New
Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
Dim sr As IO.StreamReader
Dim wc As New System.Net.WebClient
Dim strUrl As String
Dim strOut As String = ""
strUrl = "http://xml.weather.yahoo.com/forecastrss?p=32927"
Try
sr = New IO.StreamReader(wc.OpenRead(strUrl))
Dim strHtml As String = sr.ReadToEnd
Dim x As Integer = strHtml.IndexOf("<img src")
Dim y As Integer = strHtml.IndexOf(")<br/>")
Try
strOut = strHtml.Substring(x, y - x + 6)
Catch ex As System.ArgumentOutOfRangeException
' thrown by : System.String.Substring(System.Int32,System.Int32)
' description :startIndex plus length indicates a position not within this instance.-or- startIndex or length is less than zero.
End Try
sr.Close()
Catch
strOut = "<h1>Error getting weather</h1>"
Finally
writer.Write(strOut)
End Try
End Sub
End Class