Skip navigation.

Weather Custom Server Control

Comment permalink 1 Li-Ping |
Hi there

I believe the "i" element in complex type element "uv" of your weather.xsd should be of type "xs:string".

E.g. for location SNXX0006, the returned value is "10+".
Comment permalink 2 Milan Negovan |
10+? Wow. Didn't realize it was a string. Weather.com only provides a DTD schema and you can't tell the data type of each field, so I had to make an "educated guess" here and there. Thanks for pointing it out!
Comment permalink 3 Li-Ping |
http://www.epa.gov/sunwise/uvilaunch.html

Yes, apparently us folks at the equator have it pretty darn warm. ;)
Comment permalink 4 pick-master |
Regarding the png transparency issue, I found this URL that provides a solution.

http://homepage.ntlworld.com/bobosola/pnghowto.htm
Comment permalink 5 Milan Negovan |
Thanks! I'm including this PNG fix with the demo page.
Comment permalink 6 Steven |
This is terrific! Could your control support forecast information as well as the current temperature? Thanks!
Comment permalink 7 Milan Negovan |
The control has 'Temperature' and 'FeelsLike' properties. I will add 2 and/or 5 day forecast information in the next release.
Comment permalink 8 Rick |
How would i include this page into my template page (CSK VB)?
I can get the page to work outside my main site, just not sure how to add to page.
Thanks
Comment permalink 9 Shannon J Hager |
I am using this weather control in a pet project site I am currently working on and today I ran into a pretty bad error handling problem. I am not exactly sure where the error came from but I think it was due to a DNS problem or possibly network problems where the server is hosted (there were no problems on the local mirrored version of the site). The page errored with a "connection was terminated: could not resolve remote [name? server? I forgot]" error. It was definitely from the weather control, but I'm not sure if it was a DNS problem (not being able to reach the weather service?) or if the service threw an error (unable to reach its database?). The problem only lasted 4 or 5 minutes but I had to remove the control from my page templates in order to get the pages to work. I had similar problems when I tried to work on the site when the server wasn't allowed to hit the Internet. I know that normal usage would dictate that Internet access is required but I think adding another try/catch or something and displaying a generic "Weather Service Currently Unavailable" message would be the way to go.
I have also considered serializing the current conditions to disk (I only check the service every 30 minutes) and using those results if the service is down.

While I'm here, THANKS! This is a great server control, I was a bit surprised (thought I should have known) that, after dropping it onto my ASP.NET page, the page still was still valid xhtml trans. Good job and thanks again.
Comment permalink 10 Milan Negovan |
The control allows you to craft your own markup, so it's your accomplishment that your page is valid XHTML Transitional, not mine. :)

Good point about error handling. I need to do a better job at handling errors when weather.com itself goes down or an Internet connection is not available.
Comment permalink 11 Rozanne |
I want to start off by saying, wow,thanks. This is a lovely control, beautifully documented too. I discovered it earlier this afternoon and it's been a joy to work with. I'm modifying the control for a dotnetnuke module of mine, to display the weather conditions for a user, and to allow them to enter a different US zip code. It all works nicely - but after refreshing, the image no longer displays correctly. Is there a reason for this? Here is my code:

Dim wccControl As New UserController
Dim zipcode
zipcode = Trim(Me.txtZIP.Text)

If zipcode = "" Then
If Not (MyBase.UserId = -1) Then
Dim x As UserInfo
x = wccControl.GetUser(0, MyBase.UserId)
wccWeather.LocationID = Trim(x.PostalCode)
Me.lblDebug.Text &= ("Setting locationID from userdata: " & Trim(x.PostalCode))
End If
Else

Dim isvalid
isvalid = IsValidZip(zipcode)
If isvalid "" Then
Me.lblfeedback.Text = isvalid
Me.lblfeedback.Visible = True
Exit Sub
Else
Me.lblfeedback.Visible = False
End If
wccWeather.LocationID = Trim(Me.txtZIP.Text)

Me.lblfeedback.Text &= ("Setting locationID from zip box: " & Me.wccWeather.LocationID)
Me.lblfeedback.Visible = True
End If
wccWeather.DataBind() -- this is where I think it's somehow losing the image path??
Comment permalink 12 Rozanne |
It's ok ... found it ;-) I moved the location of the ccimages folder. I'm not sure how the images were found, correctly, for the first time the app loaded, if they were in the incorrect location ... but moving them did the trick.
Comment permalink 13 Milan Negovan |
Rozanne, I'd like to know a little more about what happened there and how you solved it. If it happened once, it's bound to happen again. :)
Comment permalink 14 Nikhil Kothari |
Looks pretty cool...
Comment permalink 15 Steve Quarles |
I registered with Weather.com and received my PartnerID and License Key and added the anrControls.Weather.dll as a reference along with creating a ccimages folder and copied the images in. My problem is the control says "Weather forecast is not available at this time." Am I missing something? If I put all the controls from the WeatherControl I get errors when running the project.

Thank you.
Comment permalink 16 Milan Negovan |
I suggest you wire its Error event, as I described in a recent post (it's also shown in the sample). If you develop in VS.NET see what the exception message is. Otherwise simply print out the error on the page and let me know what it says.
Comment permalink 17 Damir |
Can you provide some info how to install yours component to WebMatrix. I try with "Add Local Toolbox Component" and select anrControls.Weather.dll.
An Error occurred: "No valid Web controls were found in the assembly" after that I must delete *.dll from ..\WebMatrix\components folder but when I try to run demo next error occured: Parser Error Message: 'WeatherControlTest.defaultTest' is not a valid base class because it does not extend class 'System.Web.UI.Page'.
Source Error:
Line 1: [%@ Page Language="c#" autoeventwireup="false" codebehind="default.aspx.cs" Inherits="WeatherControlTest.defaultTest" %]

thx
Damir
Comment permalink 18 Eric |
hi
i ve got a pb in WeatherData.BuildImageUrl method

Assembly.GetExecutingAssembly().GetManifestResourceStream (resourceName) always return null

but i ve got added in weather control project all images provided by weather.com

Any idea ?
Comment permalink 19 Eric |
I found the problem

The images was not marked as "Embedded Resource" in the weather project.


Another question :
Is there a way to display the next day weather forecast ?
Comment permalink 20 Milan Negovan |
Yeah, these is a way. I need to add a forecast template some time in the future and pull down a different XML feed---one that has a forecast for several days ahead.
Comment permalink 21 Bob |
First I would like to thank you for posting this excellent control. I have a question on your 'Resolve Weather Location ID'. Is this being resolved locally or via weather.com? If the latter, are you going to make the code to replicate this available? Thanks.
Comment permalink 22 Milan Negovan |
Bob, I was so sure I published the code before... but I guess I didn't. I zipped up the ASPX page and its code behind for download.

In a nutshell, weather.com resolves location ID and returns an XML document with all matching locations.
Comment permalink 23 Luke |
I am having a problem using your Weather Control. I am getting
Weather forecast is not available at this time. I have taken the URL you had in your code and plugged my values into it and go XML back from weather.com. Any ideas? I also see they images were not included in your download. Will this case this error?

Thanks
Comment permalink 24 Milan Negovan |
Luke, take a look at this post. It explains how you can inspect what goes wrong.

Also, images are embedded in the assembly and get extracted at run time.
Comment permalink 25 Luke |
Milan thanks for the reply here is what i got for an error.

The Weather control should contain a WeatherTemplate element

Luke
Comment permalink 26 Milan Negovan |
Luke, look carefully through the sample page included in the download. The control should have a declaration of WeatherTemplate.
Comment permalink 27 Luke |
Ahh I see. Thanks alot for your help.

Luke
Comment permalink 28 Luke |
I am having a problem regarding my WeatherTemplate. The Weather Control does not seem to be updating my form schema to allow for the WeatherTemplate. The control does still work, but when I make a changed to the control through the designer it deletes my Template. Any Ideas?
Thanks
Comment permalink 29 Milan Negovan |
Luke, I believe someone mentioned it to me before, but I haven't figured out how to stop VS.NET from deleting the template. Not sure why it's happening. The only workaround I can suggest is not to use the VS.NET designer, which is aweful anyway.
Comment permalink 30 New Zealand Web Hosting |
Thankyou very much for the link!

We are going to implement this in our website!
Comment permalink 31 Gonzalo |
Hi, I'm working on a version with days forecast support.
I want it to know how can I do to define equals entries on the xml (for example "wind" for cc and "wind" for first day) and the Generator of .NET doesn't give me this error:

Custom tool error: Unable to convert input xml file content to a DataSet. The same table (wind) cannot be the child table in two nested relations.

I know... the problem is that define equals tables (in the DataSet) with the same name, but how can I resolve the problem?

Thanks,
Gonzalo
Comment permalink 32 Milan Negovan |
Hmm... That's an interesting question, Gonzalo. I imagine there will be a name clash, as you pointed out. I wonder if you need to write your own XmlReader for that.
Comment permalink 33 Sam Parsons |
Wow, thank you so much! You made my day.

Quick question though: Does the control automatically cache the XML to the specifications outlined in the SDK?

Thanks again!
Comment permalink 34 Milan Negovan |
Sam, yes, as the SDK prescribes, weather conditions are cached for 30 minutes for each location (one location in this case).
Comment permalink 35 Brian |
Great Control! The download is missing the PNG's now.. any chance of getting them put back in?
Comment permalink 36 Milan Negovan |
My bad. They are in now. Thanks for heads-up, Brian.
Comment permalink 37 Joe Huddleston |
I have your sample and I am trying a simple page, but cannot get anything other than the error "Forecast not available." I can access the xml page and have a template defined, but I cannot figure out what is causing the error. Even when using VS.net and stopping after initializingcomponent (VB) I still see no error being thrown.

Any help would be great. I would like to write out the error to the page using VB, but have not been successful.
Comment permalink 38 Joe Huddleston |
Got my error....
System.Net.WebException: The underlying connection was closed: [...]
Comment permalink 39 Joe Huddleston |
I think I have this narrowed down but still do not know how to solve.
The Event viewer show me trying to access http with the IUSR account. My IUSR account will not have permission for this and I need to impersonate. However, when I impersonate the impersonation does not seemed to be used by the weather control.
Comment permalink 40 Milan Negovan |
Joe, have you followed the suggestions in this post to troubleshoot the problem? As far as permissioning is concerned, I'm afraid I don't have much insight into that.
Comment permalink 41 Joe Huddleston |
Yes, I followed that post. That is how I determined it was having authentication problems. Has anyone had any success in implementing the with a proxy requiring authentication?
Comment permalink 42 Joe Huddleston |
If I was a bit more knowledgable in C# and these controls I might be able to implement the forth coming suggestion and just tell you about it.

I believe some code similar to the below will allow users needing to authenticate to do so. Passing the domain, user, and passsword would be most ideal.

WebProxy myProxy = new WebProxy("http://proxyserver:port",true);
myProxy.Credentials = new NetworkCredential("username", "password", "domain");
FindServiceSoap myFindService = new FindServiceSoap();
myFindService.Proxy = myProxy;
Comment permalink 43 Milan Negovan |
Joe, thanks for the tip. You da man!
Comment permalink 44 Joe Huddleston |
New error, but i don't kno wi fthis is progress
System.Net.WebException: The underlying connection was closed: The proxy name could not be resolved

//NetworkCredential nc = new NetworkCredential("user", "pass", "domain");
XmlUrlResolver resolver = new XmlUrlResolver();
resolver.Credentials = system.Net.CredentialCache.DefaultCredentials;
doc.XmlResolver= resolver;

Added these to WeatherData.cs above the Doc.Load. Requires using System.Net.
I tried defining condition explicitly and using DefaultCredentials. Same error both times.

I hope you don't mind me using this as a debug stop. I am hoping to find someone that knows something.

Your product looks great and I hope to use it.
Comment permalink 45 Joe Huddleston |
This finally worked

< defaultProxy >
< proxy
usesystemdefault = "false"
proxyaddress="http://proxyserver:80"
bypassonlocal="true"
/>
< /defaultProxy >
Comment permalink 46 Andy |
The code works just great in sub directories but when i take it to the top parent directory it does not work. Also I tried to use the code as a user control and there seems to be a diconnect again, giving me the standard error message. Does anyone have an idea how to use this in a ASP.NET setting as a user control? Thanks for your assistance!!
Comment permalink 47 Rui Marques |
Excelent article... In one article i found all i need to know about how to user weather.com feeds in a ASP.NET application.

Thanks!!!
Comment permalink 48 Bill |
I am trying to use a textbox and a button to get the new zip from the user and trying to assign the value to weaControl.LocationID property. The problem is the first time I click the button no change occurs, when I click the button again for the second time the control is changing the values. I thougt its problem with my .net framewrok, but everything else is working fine.
Example
If I enter a zipcode 10001 in the text box and click the button no change occurs, the second time I changed the zip to 73301 and click on button, the control displayed the information for zip 10001. for your reference I am providing the code I wrote in the code behind.
Private Sub ZipButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ZipButton.Click

If ZipText.Text "" Then
Weather1.LocationID = Trim(ZipText.Text)
Else
Weather1.LocationID = "10001"
End If
Weather1.DataBind()
End Sub
Comment permalink 49 Manic |
Could you make a light version of this component (without png images in dll). This dll is to large
Comment permalink 50 Milan Negovan |
No, because you'll have to manage images yourself which would make usage of this component awkward. I'd rather keep them embedded.
Comment permalink 51 Deepak |
hi,
when i tried to use ur custom control in my aspx page,it is displaying as "Weather forecast is not available at this time"...

I registered with Weather.com and received my PartnerID and License Key and added the anrControls.Weather.dll as a reference

when i dubeg the custom control code ,i noticed these specific below line in "Weather.cs" file

ITemplate template = this.WeatherTemplate;

this "template" variable is getting null,so it is throwing error as "Weather forecast is not available at this time"

What was suppose to be valued in that "template" varibale..
plz reply me with some soultion to deepak.ramaiah@hotmail.com

my last question ,is there any webservice from wether.com or from any organisation which can display us wether forecast of world..
if there is any such webservice,plz let me knwon...

I am using VS.NET 2003

Thank u
Deepak
Comment permalink 52 Milan Negovan |
Deepark, please re-read the article. It talks about the web service at weather.com you are looking for. Their feed gives you enough information about any location in the world.
Comment permalink 53 Tryst |
So can this be applied to Windows Forms? Maybe I can present this data to controls in a Panel?

Tryst
Comment permalink 54 Milan Negovan |
Trystan, I distribute this component with source code. I think it should be possible to turn it into a WinForms control. I'm just not familiar with that side of control development.
Comment permalink 55 Saint_77 |
Very nice control indeed .... how long before your control will support any forecast information? How soon will a release be available that will support forecast information?
Thanks
Comment permalink 56 Milan Negovan |
I don't really have a time frame for this. I make my code available for free, so if anyone wants to extend the control it'd be great.
Comment permalink 57 saju |
Hi,
when i used the custom control in my aspx page,it is displaying as "Weather forecast is not available at this time"...

I registered with Weather.com and received my PartnerID and License Key and added the anrControls.Weather.dll as a reference
Comment permalink 58 Michael Hutchison |
Nice control. I am having a problem and others too, I see. The control works without any problems on my development machine. On root level pages as well as sub folders. However, when I upload the files to the live site, the root level works but the sub-levels do not. Any help would be greatly appreciated.
Comment permalink 59 Milan Negovan |
Saju, Michael,

Take a look at this post for troubleshooting tips. Also, make sure the folder where images go has write permissions granted to the ASPNET account (NetworkService in Windows 2003 Server).
Comment permalink 60 Nico |
Wel let me start by complementing you on a very handy component.
But i have one question. How can i display more than 1 day at a time.
Comment permalink 61 Milan Negovan |
It takes a different query to the weather.com web service to get a forecast for several days. I don't really plan on doing it, but if anyone wants to implement it, please share. :)
Comment permalink 62 Bill Youngman |
I'm using your control in a client's intranet site and they love it. Now they would like to see the forcast along with the other data and I'm trying to accomodate them but I'm running into a problem. I took your code and am using it as a framework and added the forcast elements from the Weather.com sdk to the .xsd file and am in the process of adding the properties to the dll in order to display them in the web page. The problem I'm running into is that dataset returned from Weather.com has data for the stuff like cc, flik etc. but it's showing no rows for the stuff that I added day, hi - etc.

I would appreciate any suggestions/assistance as the documentation from weather.com is pretty poor.

Thanks
Comment permalink 63 Brett |
I just downloaded your control and am playing around with the weathercontroltest version. I have added a text box so that a user can enter a new zip code. However, hitting subit does not change the data displayed. Can you let me know what I am doing wrong?

I am using the code below:

Protected Sub btnZip_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnZip.Click
Weather1.LocationID = txtZip.Text
Weather1.DataBind()
End Sub

It seems like it should work, but I have had no luck. Thank you for the help and for the great work.
Comment permalink 64 Boris |
Brett,
I think the problem is with the page life cycle. I found the solution but I think that my solution isn't the best way to do it. Anyway, here is how I solved it:
When the user hits the btnZip, read the txtZip and store it somewhere (for example in Session) and redirect to some other page (for example test.aspx). On test.aspx in Page_Load method redirect back to your first page and in the first's page Page_Load method set the LoacationID.
Comment permalink 65 Leon |
This is just a fantastic control. I got the current weather displayed on my site, but I now need the forecast data as well. Id this even possible iun the current version? The zip file I downloaded did not contain any documentation. Any help would be greatly appreciated. And again, thanks for the great work!
Comment permalink 66 Milan Negovan |
Leon, please see this comment.
Comment permalink 67 Charles |
Does anyone know the steps needed to install and use this weather.com control.

I have so far done the following:

Added anr.Controls.weather.dll to the bin folder

Added a reference to anr.Controls.weather.dll

Added the control to my page

Added the PartnerID and License Key

Added the LocationID

Added the ccimage folder and files to my project

But I still get the 'Weather forecast is not available at this time. ' when I run the app.

I appreciate any help,
Comment permalink 68 Milan Negovan |
Charles, see this post. I exposed an error event which you can tap into and see what's going wrong.
Comment permalink 69 Leon |
Decided to go another route and did the forecast part myself.

here you go...

http://www.codeproject.com/useritems/weathercontrolVB.asp
Comment permalink 70 Milan Negovan |
Very cool!
Comment permalink 71 Brijesh |
Could you please help me to find the location ID of Singapore.

Thanks!

Looking for the responces...
Comment permalink 72 Milan Negovan |
Very strange, weather.com won't give me a location Id for Singapore either. :(
Comment permalink 73 Milan Negovan |
Try "SNXX0006". If it doesn't work, pick one of these locations.
Comment permalink 74 Fatih |
That's fantastic.

Thank you so much.
Comment permalink 75 Peter Konstant |
Hello,

First, I want to thank you for putting this control together and documenting it.

I have VS 2008 and tried to compile your control but I get two errors:

Error 1 The namespace 'anrControls' already contains a definition for 'Weather' weather.Designer.cs Weather
Error 2 The namespace 'anrControls' already contains a definition for 'Weather' WeatherDataError.Designer.cs Weather

Do know what is wrong?

Many Thanks, Peter
Comment permalink 76 wah |
Awesome control, nice man.

Submit your comment

Please enter only text since all HTML tags except hyperlinks will be stripped. Hyperlinks will become live links. Any comments with flaming or offensive language will be deleted. Be courteous to other posters. Thank you.

Your name (required):
Your email (optional):
Your site's URL (optional):
Enter this number
Type in the number above:
Comment (required):