Visual Basic .NET Forums    

Go Back   Visual Basic .NET Forums > ASP.NET > Component Development

VB.NET Forums Newsletter Signup:
Email address:


Component Development Discussion on developing web controls

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-21-2008, 1:10 PM
VB.NET Forum Newbie
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Aug 2008
Age: 50
Posts: 2
Reputation: 0
nakins is on a distinguished programming path ahead
Default converting DLL to ascx?

Hello,
I found a VS project that is a weather control which gets an xml file from default (National Weather Service) and parses it to deliver a 3 day forecast.
This comes from ASP.NET 2.0 US Weather Forecast Custom Control and is all in a zip file. There is a completed DLL and aspx and other supporting files to make it work, as is, on a web page.

I would like to use this feed/webservice as it is free and with no strings attached. However, I need to make changes in how the info is laid out and displayed. I also would like to display my own images as opposed to the fetched ones.

I believe I have found the file I need to use in order to create a ascx, but I'm not sure if the code below is all that is required. Also, I'n not sure what to add/remove in order to make it work, such as converting it from a dll to an ascx. I do have some experience with vb, building aspx pages, mostly dealing with database i/o.

I would really appreciate any advice, suggestion, or direction in how to convert this to an ascx.

Thank you

Code:
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Text
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
'Imports System.Xml


<ToolboxData("<{0}:Forecast runat=server></{0}:Forecast>")> _
Public Class Forecast
    Inherits WebControl

#Region "Declarations"

    Private mForecast As net.webservicex.www.WeatherForecast
    Private WxDetails() As net.webservicex.www.WeatherData
    Private Wx As net.webservicex.www.WeatherForecasts

#End Region


#Region "Methods"

    Private Sub Forecast_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init

        If Not String.IsNullOrEmpty(ZipCode) Then
            GetWeather(ZipCode)
        Else
            GetWeather("36201")
        End If

    End Sub

    Public Sub GetWeather(ByVal zip As String)

        Try
            mForecast = New net.webservicex.www.WeatherForecast
            Wx = mForecast.GetWeatherByZipCode(zip)
            WxDetails = Wx.Details
        Catch
            Exit Sub
        End Try

    End Sub

#End Region


#Region "Properties"

    <Category("Weather"), Description("Set Forecast Zip Code"), Browsable(True)> _
    Property ZipCode() As String
        Get
            Dim s As String = CStr(ViewState("ZipCode"))
            If s Is Nothing Then
                Return String.Empty
            Else
                Return s
            End If
        End Get

        Set(ByVal Value As String)
            ViewState("ZipCode") = Value
        End Set
    End Property

#End Region



#Region "Rendering"


    Protected Overrides Sub RenderContents(ByVal output As HtmlTextWriter)

        ' the web service actually returns seven days, I am just using the 
        ' first three days to make a 3 day forecast but the additional days
        ' could be added in a similar manner

        Try
            ' set padding and start the table
            output.AddStyleAttribute(HtmlTextWriterStyle.Padding, "3")
            output.RenderBeginTag(HtmlTextWriterTag.Table)

            ' display location information based on zip code
            ' in first row of the table
            output.RenderBeginTag(HtmlTextWriterTag.Tr)
            output.RenderBeginTag(HtmlTextWriterTag.Td)
            output.Write("<b>Location:  </b>" & Wx.PlaceName.ToString() & ", " & _
            Wx.StateCode.ToString() & "<br/>")
            output.Write("<b>Zip Code:  </b>" & ZipCode & "<br/>")
            output.Write("<b>Lat/Long:  </b>" & Wx.Latitude.ToString() & _
            "/" & Wx.Longitude.ToString() & "<br/>")
            output.RenderEndTag()
            output.RenderEndTag()

            ' display highs and lows for day 1
            output.RenderBeginTag(HtmlTextWriterTag.Tr)
            output.RenderBeginTag(HtmlTextWriterTag.Td)
            output.Write("<hr/>")
            output.Write("<b>  Day:       </b>" & WxDetails(0).Day.ToString() & "<br/>")
            output.Write("<b>  High/Low:  </b>" & WxDetails(0).MaxTemperatureF.ToString() & _
            "/" & WxDetails(0).MinTemperatureF.ToString() & "<br/><br/>")
            output.RenderEndTag()
            output.RenderEndTag()

            ' get weather service image and add it to control
            output.AddAttribute(HtmlTextWriterAttribute.Align, "center")
            output.RenderBeginTag(HtmlTextWriterTag.Tr)
            output.RenderBeginTag(HtmlTextWriterTag.Td)
            Dim img As New Image()
            img.ImageUrl = WxDetails(0).WeatherImage.ToString()
            img.BorderStyle = WebControls.BorderStyle.Inset
            img.BorderWidth = 2
            img.RenderControl(output)
            output.RenderEndTag()
            output.RenderEndTag()

            ' display highs and lows for day 2
            output.RenderBeginTag(HtmlTextWriterTag.Tr)
            output.RenderBeginTag(HtmlTextWriterTag.Td)
            output.Write("<hr/>")
            output.Write("<b>Day:       </b>" & WxDetails(1).Day.ToString() & "<br/>")
            output.Write("<b>High/Low:  </b>" & WxDetails(1).MaxTemperatureF.ToString() & _
            "/" & WxDetails(1).MinTemperatureF.ToString() & "<br/><br/>")
            output.RenderEndTag()
            output.RenderEndTag()

            ' get weather service image and add it to control
            output.AddAttribute(HtmlTextWriterAttribute.Align, "center")
            output.RenderBeginTag(HtmlTextWriterTag.Tr)
            output.RenderBeginTag(HtmlTextWriterTag.Td)
            Dim img2 As New Image()
            img2.ImageUrl = WxDetails(1).WeatherImage.ToString()
            img2.BorderStyle = WebControls.BorderStyle.Inset
            img2.BorderWidth = 2
            img2.RenderControl(output)
            output.RenderEndTag()
            output.RenderEndTag()

            ' display highs and lows for day 3
            output.RenderBeginTag(HtmlTextWriterTag.Tr)
            output.RenderBeginTag(HtmlTextWriterTag.Td)
            output.Write("<hr/>")
            output.Write("<b>Day:       </b>" & WxDetails(2).Day.ToString() & "<br/>")
            output.Write("<b>High/Low:  </b>" & WxDetails(2).MaxTemperatureF.ToString() & _
            "/" & WxDetails(2).MinTemperatureF.ToString() & "<br/><br/>")
            output.RenderEndTag()
            output.RenderEndTag()

            ' get weather service image and add it to control
            output.AddAttribute(HtmlTextWriterAttribute.Align, "center")
            output.RenderBeginTag(HtmlTextWriterTag.Tr)
            output.RenderBeginTag(HtmlTextWriterTag.Td)
            Dim img3 As New Image()
            img3.ImageUrl = WxDetails(2).WeatherImage.ToString()
            img3.BorderStyle = WebControls.BorderStyle.Inset
            img3.BorderWidth = 2
            img3.RenderControl(output)
            output.Write("<br/><br/>")
            output.RenderEndTag()
            output.RenderEndTag()

            ' close the table
            output.RenderEndTag()

        Catch

            ' the control will not render without contacting the web service
            ' so just display text if the data is unavailable or the web 
            ' service web method has not be evoked
            output.Write("Weather Report Control")

        End Try

    End Sub

#End Region


End Class
Reply With Quote
  #2 (permalink)  
Old 08-21-2008, 3:43 PM
JohnH's Avatar
VB.NET Forum Moderator
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Dec 2005
Location: Norway
Age: 36
Posts: 7,894
Reputation: 819
JohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond repute
Default

ascx is the extension for user controls, Add a "Web User Control" to your project, then use the visual designer to design it like any other Asp.net page. Add code-behind when you have the UI ready. That means most of your code in RenderContents is redundant.
__________________
See this thread about how to use forum markup codes for code blocks etc (present the problem/post properly )
Some useful links: Learning videoes, WMI Code Creator, MSDN, The Code Project, WindowsClient.net, ASP.net, W3 Schools, Regular-Expressions.info, GDI+ FAQ


DR. WEIR: Download it to a non-networked, firewalled computer.
TECHNICIAN: Yes, ma'am.
Reply With Quote
  #3 (permalink)  
Old 08-21-2008, 3:59 PM
VB.NET Forum Newbie
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Aug 2008
Age: 50
Posts: 2
Reputation: 0
nakins is on a distinguished programming path ahead
Default

I believe you might have missed the point of my post. I already know how to add an ascx. My question is how to know what parts of this code are particular to Visual Studio and of those how or what to I use to make the code work as an ascx.
Reply With Quote
  #4 (permalink)  
Old 08-21-2008, 4:41 PM
JohnH's Avatar
VB.NET Forum Moderator
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Dec 2005
Location: Norway
Age: 36
Posts: 7,894
Reputation: 819
JohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond repute
Default

Oh, you didn't write this code, you just copied it and wonders what it does? The essence is consuming a webservice, see for example Creating and Consuming a Web Service, Part 2 . In short regarding your posted code a variable is declared to hold the service reference and a new instance is created:
Code:
Dim mForecast As New net.webservicex.www.WeatherForecast
then you can interact with the service methods:
Code:
Dim Wx As net.webservicex.www.WeatherForecasts = mForecast.GetWeatherByZipCode(zip)
LabelPlace.Text = Wx.PlaceName
The namespace (net.webservicex.www) could be different when you add the web reference.
__________________
See this thread about how to use forum markup codes for code blocks etc (present the problem/post properly )
Some useful links: Learning videoes, WMI Code Creator, MSDN, The Code Project, WindowsClient.net, ASP.net, W3 Schools, Regular-Expressions.info, GDI+ FAQ


DR. WEIR: Download it to a non-networked, firewalled computer.
TECHNICIAN: Yes, ma'am.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT -4. The time now is 3:05 PM.




Click to advertise here

Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
For advertising opportunities click here.