Weather Forecast ASP.NET user control

I am posting source code for the weather report control that I am using on my Web site. It looks like this:

Weather forecast control preview

It fetches weather forecast data from a free XML Web service provided by US National Oceanic and Atmospheric Administration (NOAA). There is a lot of data there (wind speed and direction, humidity, precipitation, etc). I only used some of it. I believe the data is for US only so it won't work for every geographical location.

There is no copyright of any kind, feel free to use the code any way you see fit. If you don't like the code or markup, don't shoot me, I am only a C++ developer 🙂

Updated version:

Comments (25)

  1. Pretty cool stuff! Now all you need is to hook it up to USGS database for automatically determining lat/long from the city name:

  2. Mark says:

    Cool stuff indeed – I wish I could put one of your weather images to show it!

  3. Mikhail Arkhipov (MSFT) says:

    In fact, icons are provided by NOAA as part of their Web service (very nice of them!).

  4. John says:

    I wanted to use this on a VB ASP.Net applications, but I can’t just include the files, since it appears you can’t mix VB and C# in the same project. I wanted to compile it into an assembly, but it doesn’t look like Web Control libraries support ASCX user controls – just .CS classes. Any thoughts? Thanks!

  5. Just wanted to add another comment thanking you for your code and your benevolence to give it away. It’s too bad NOAA doesn’t provide real time weather data. They provide XML feeds for all of their weather stations ( but many of them don’t even have Latitude/Longitude coordinates — what’s the point of that? Anyway, this code gets me one step closer to a fully functional weather service.


    Kevin Grigorenko

  6. Eric says:

    Well done! Thanks for sharing this.

  7. Advait says:

    I need to use ur control how do i use it i have downloaded ur zip but help me in using the tool pls

  8. Brian Evans says:

    Hi, I was wondering if there is something more to this. I have added your code and control to my solution. I dragged the control onto my form and made sure the control had the parameters you show in your README file but when I run the page nothing shows up. Any help is much appreciated. Also, thanks for the code!!!

  9. Brian Evans says:

    I am getting an Exception thrown in the ParseWeatherXML method. I do have a string value passed into this method but the exception is thrown anyway. Any help?

  10. The control stopped working on my own Web site as well. I guess NOAA might have changed something in their XML data. I’ll try to debug when I get some spare time.

  11. Tim Daley says:

    I am posting this link here to help those who dont have this user control working atm. Maybe you can update the stream and such and that may fix your issues with this.

  12. rakesh says:

    could u u tell me how i can use weather in my c# application.

  13. rakesh says:

    i m using weather usr control.

    i m getting this error.

    could u help in this way.

    System.Net.WebException: The underlying connection was closed: The server committed an HTTP protocol violation. at System.Web.Services.Protocols.WebClientProtocol.GetWebResponse(WebRequest request) at System.Web.Services.Protocols.HttpWebClientProtocol.GetWebResponse(WebRequest request) at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters) at latitude, Decimal longitude, String product, DateTime startTime, DateTime endTime, weatherParametersType weatherParameters) in C:InetpubwwwrootWeatherWeb 38 at Weather.WebForm1.Page_Load(Object sender, EventArgs e) in c:inetpubwwwrootweatherwebform1.aspx.cs:line 92



  14. OS says:

    Can someone clarify – does NDFD provide only FUTURE data or can I fetch historical weather data? What I’m really looking for in my application is ability to get historical data from days/weeks ago.

  15. Deepak says:


    Excellent stuff ..!

    i would like to use this..!

    But i just want to get wehter forecast information of gulf contries…So there is any webservice URL which give us weather forecast information of gulf coutries(whole world)…

    any body having any info regarding this…plz reply me…

    Thank u


  16. j. smith says:

    I’m in the middle of testing Weather forcast ASP.NET user control, the problem that gets me stumped is the follow (any ideas in resolving this issue)?

    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.Net.WebException: The request failed with the error message:



    <title>301 Moved Permanently</title>


    <h1>Moved Permanently</h1>

    <p>The document has moved <a href="">here</a&gt;.</p>

    <hr />

    <address>Apache/2.0.46 (Red Hat) Server at Port 80</address>



    Thank you!

    j. smith

  17. M. McMorrine says:

    I had this issue also.  I searched the entire project for the text "ndfdXMLserver.php" and found two lines in two documents that were pointing to URL’s that have apparently moved.  Copy the URL "; and replace the URL from the results you find from your search with the one copied.

    That worked for me, but now the issue is the error "System.Net.WebException: The underlying connection was closed: The server committed an HTTP protocol violation." which was posted above with no resolution.  Microsoft explains this error is the result of increased security in the machine.config file.  The recommend adding a statement in there to remedy it, but that did not work for me.

  18. Bert Linert says:

    I can’t resist appreciating the owners of this blog. Good information. Well Done.

    Bert Linert

  19. nookala says:

    I’m testing Weather forcast ASP.NET user control and I am getting the following error. I did everything as per the instructions given in the Readme.txt file.

    Server Error in ‘/Weather’ Application.


    Compilation Error

    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message: CS0246: The type or namespace name ‘DayWeatherData’ could not be found (are you missing a using directive or an assembly reference?)

    Source Error:

    Line 46:             try

    Line 47:             {

    Line 48:                 DayWeatherData[] arrDayWeather;

    Line 49:                 DateTime dtStart = new DateTime(DateTime.Now.Year, 1, 1, 0, 0, 0);

    Line 50:                

    Source File: http://localhost/Weather/WeatherControl.ascx    Line: 48



Skip to main content