I have a weather UserControl (defaulting to the headquarters location) . I have removed the ability to "Edit Web Part" because of branding and not wanting to have to train users on how to work the "Edit Web Part" box of goodies.
Instead of them using that, I have put a textbox in the webpart for them to enter in the zip code.
For some reason I am having a hard time grasping how to set the value of the zip code to the appropriate value in the code behind. I have posted my code below (for everything incase I have other areas I am messing things up).
weather.cs
protected override void CreateChildControls()
{
//base.CreateChildControls();
weatherUserControl control = (weatherUserControl)Page.LoadControl(_ascxPath);
control.ParentWebPart = this;
Controls.Add(control);
}
[Category("Configuration"),
Personalizable(PersonalizationScope.User),
WebBrowsable(true),
DefaultValue("<valid zip code here>"),
WebDisplayName("Zip Code"),
WebDescription("Please enter zip code")]
public string pZipCode
{
get;
set;
}
weatherUserControl.ascx.cs
public weather ParentWebPart
{
get;
set;
}
protected void btnSubmitZipCode_Click(object sender, EventArgs e)
{
ParentWebPart.pZipCode = txtZipCode.Text; // Not positive about this section
}
protected void Page_Load(object sender, EventArgs e)
{
string setZipCode = "valid zip code here"; // because the default value was not working
//if (ParentWebPart.pZipCode.ToString() != "")
//{
// setZipCode = ParentWebPart.pZipCode.ToString();
// the default value is not working
//}
XmlDocument myXml = new XmlDocument();
myXml.Load("http://weather.yahooapis.com/forecastrss?p=" + setZipCode);
}
weatherUserControl.ascx
<asp:TextBox ID="txtZipCode" runat="server"></asp:TextBox>
<asp:Button ID="btnSubmitZipCode" CssClass="button" runat="server"
Text="Set" onclick="btnSubmitZipCode_Click" />
At present the above code doesn't throw an error, but it doesn't work. Any thoughts?