Reply to topic
New User Control - Current Weather
Josh
Forum Regular

Joined: 01 Apr 2004
Posts: 1029
Location: Felton, Delaware
Reply with quote
Okay I just finished this user control. All it does is display the weather, but it saves alot of legwork. Let me know what you think, and what I can do to improve on this. Thanks!!!

Source: http://www.joshandbrandi.com/aspnet_weather_usercontrol.zip

UPDATE: This has been updated to accomodate a change made by the national weather service AND with the newest version of Dean Edwards IE7.


Last edited by Josh on Thu Dec 08, 2005 11:43 pm; edited 3 times in total
Josh
Forum Regular

Joined: 01 Apr 2004
Posts: 1029
Location: Felton, Delaware
Reply with quote
*resolved.


Last edited by Josh on Wed Jun 01, 2005 3:50 pm; edited 1 time in total
cpnet


Joined: 03 Nov 2004
Posts: 135
Reply with quote
What URL are you passing to GetRss? I tried a C# WinForms and ASP.NET project, and both can do what GetRss is doing, when I use the URL: http://weather.gov/data/current_obs/KDOV.xml .

In C#, I can't do the equivalent of:

dim level as Integer = 0
dim DS as New DataSet(level)

since level is an integer. But I can do the equivalent of

dim DS New DataSet("0")

I doubt this is the source of the problem though. Maybe your code is using a different URL (I tried to figure out what one you were probably using based on the defaults in your code). Or, maybe you're going through a proxy server that is doing something that's causing problems?
Josh
Forum Regular

Joined: 01 Apr 2004
Posts: 1029
Location: Felton, Delaware
Reply with quote
Here's the problem... it seems that the defaults being set by the property blocks are not being set... Im not sure why or what's going on... im confused to say the least. If I pass a value from my control call everything works fine... but by not including the property and a value for it it seems as if the variables are not being set. Am I setting a default value incorrectly? For instance, the default ICAO code is KDOV... but if I don't pass ICAO with the control (<msg:weather id="something" runat="server" icao="kdov" />) then nothing gets set...
cpnet


Joined: 03 Nov 2004
Posts: 135
Reply with quote
I looked again at your code, and unless there's something I don't understand about VB.NET, your property defaults won't be set unless some code first tries to set the properties to Nothing or "". Instead, I'd try:


Code:
Private _ICAO As String = "KDOV"
<DefaultValue("KDOV")>
Public Property ICAO() As String
    Get
      return _ICAO
    End Get
    Set (ByVal Value As String)
       _ICAO = CheckString(Trim(Value),"KDOV")
    End Set
End Property


This code does 2 things:

1) It makes sure that _ICAO is always initialized to "KDOV", so you don't have to rely on the "setter" being called to initialize the default.
2) It uses the DefaultValueAttribute so that if the default value is what is set in the property editor, it doesn't need to be persisted to your ASPX page. I've actually only built server custom controls before - never user controls - but I expect this attribute is still relevant.

Maybe there's some VB thing I'm not aware of, but in other languages I've worked in, you initialize property defaults in the declaration of the associated pivate field, or in the "getter" for the property. It's fine for a "setter" to maintain a default if the user tries to set a property to Nothing or "" (like your code does) but you usually can't rely on this to initialize your defaults.
Josh
Forum Regular

Joined: 01 Apr 2004
Posts: 1029
Location: Felton, Delaware
Reply with quote
Okay I think that put me on a better track. That itself did not alleviate the problem... the variables still aren't getting set. I was hoping to be able to utilize code built into the framework to perform such tasks, but if I need to I can just add some logic to page_load...

Thanks for that piece of info... I'd not have found anything else if I wasn't looking for something more specific. In the other user controls I've written, they don't take this amount of data (they're more tailored to the task at hand) and I know all the properties that need to be set... but because I'll be giving this out and posting it for download, I'd like it to be alot more "user friendly".

Unfortunatly my C++ was very minimal and extremely basic... so I never got into classes with that. .NET is my first true love Wink and the focus of my efforts. So I don't have much other experience to compare to...

EDIT: and I think I just got my answer... http://www.dotnet247.com/247reference/msgs/51/258572.aspx
cpnet


Joined: 03 Nov 2004
Posts: 135
Reply with quote
Did you try the line:
Private _ICAO As String = "KDOV"
???

Initializing your private field when you define the field (as the above code does) should be equivalent to initializing the field in a constructor. In Delphi, you always had to initialize private fields in your constructors, but I find the above method (that C# and VB.NET allow) keeps the code cleaner and easier to follow and edit (since all of the setup for the field - definition and initialization - is all done in one place).

That's the specific change that should fix your problem.

The DefaultValueAttribute is just to reduce the code in your .ASPX pages when a user leaves properties set to their default values. It will also highlight the property value in the property editior if it has been changed from the default. But, it won't help initialize the property.
Josh
Forum Regular

Joined: 01 Apr 2004
Posts: 1029
Location: Felton, Delaware
Reply with quote
I did miss that when I read your post and figured I'd just initialize the variables and see what happened... and it turns out that initializing them did the trick... Thanks for the advice. I have a habit of overcomplicating things... *shrugs* what can I say.

Anyhow, it's finished... at least as much as I'm going to do right now. It serves the purpose of everything I need it to do (and then alittle more) and the things that I need (and hopefully a few others) can be set in the aspx page... not the UC... which was my goal.

Source: http://www.joshandbrandi.com/aspnet_weather_usercontrol.zip
cpnet


Joined: 03 Nov 2004
Posts: 135
Reply with quote
It looks pretty slick... glad it's working!
Josh
Forum Regular

Joined: 01 Apr 2004
Posts: 1029
Location: Felton, Delaware
Reply with quote
Thanks Smile
Quick Question
bigheadmedia


Joined: 06 Dec 2005
Posts: 1
Reply with quote
Hey Josh,
Do you have a place where I can see your Weather Control in action? I just want to see the design route you took.
Josh
Forum Regular

Joined: 01 Apr 2004
Posts: 1029
Location: Felton, Delaware
Reply with quote
Yes I do... http://joshandbrandi.com/weather/

It's nothing fancy as it's just an add-on to any asp.net enabled website. I stuck w/ XHTML compliant code also.

EDIT:
Just noticed... the datacontainer item "visibility" got changed to "visibility_mi" so that will need updating. Other than that you're good.
Josh
Forum Regular

Joined: 01 Apr 2004
Posts: 1029
Location: Felton, Delaware
Reply with quote
UPDATE: This has been updated to accomodate a change made by the national weather service AND with the newest version of Dean Edwards IE7.
New User Control - Current Weather
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT  
Page 1 of 1  

  
  
 Reply to topic