问题设置Html页面加载后选择

时间:2010-06-18 19:26:09

标签: c# controls

我有一个C#自定义控件,用于显示地址表单。在控制中,我有一个选择你的状态。在页面加载中,我为select设置了默认值。我公开了一个公共方法,我传递一个变量来分配所有的地址信息。

我的问题是,当我运行我的方法时,选择不会更新为具有正确的选定值。有什么想法吗?

以下是背后的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

//Epicor Soap Stuff
using Clientele.Application.Client;
using Clientele.Application.Common;
using Clientele.Modules.Party.Common;
using Clientele.Modules.Party.Interface;

using System.Configuration;
using System.Net;
using System.Data;

namespace AccountCenterUserControls.Address
{
    public partial class AddressFieldSet : System.Web.UI.UserControl
    {
        //Credentials
        static String EpicorWSLogin = ConfigurationManager.AppSettings["EpicorWSLogin"].ToString();
        static String EpicorWSPassword = ConfigurationManager.AppSettings["EpicorWSPassword"].ToString();
        static String EpicorWSDomain = ConfigurationManager.AppSettings["EpicorWSDomain"].ToString();
        NetworkCredential myCredentials = new NetworkCredential(EpicorWSLogin, EpicorWSPassword, EpicorWSDomain);

        private epicor_Organization.OrganizationFullDataSet.PhysicalAddressRow _Address;

        protected void Page_Load(object sender, EventArgs e)
        {
            //Load Address Data
            epicor_ValueListEntry.ValueListEntry ValueListEntryWS = new epicor_ValueListEntry.ValueListEntry();
            ValueListEntryWS.Credentials = myCredentials;

            region.DataSource = ValueListEntryWS.GetByListID(ValueListName.PhysicalAddressRegion).ValueListEntry.Select("", "Description ASC");
            region.DataTextField = "Description";
            region.DataValueField = "Entry";
            region.DataBind();

            country.DataSource = ValueListEntryWS.GetByListID(ValueListName.PhysicalAddressCountry).ValueListEntry;
            country.DataTextField = "Entry";
            country.DataValueField = "ValueListEntryID";
            country.DataBind();

            //Set some inteligent defaults for the state/country dropdown
            country.Value = Clientele.Modules.Party.Interface.Country.USA.ToString();
            region.Value = "MD";
        }

        public void Set(epicor_Organization.OrganizationFullDataSet.PhysicalAddressRow Address)
        {
            _Address = Address;

            address1.Value = Address["Address1"].ToString();
            address2.Value = Address["Address2"].ToString();
            address3.Value = Address["Address3"].ToString();
            city.Value = Address["City"].ToString();
            zip.Value = Address["PostalCode"].ToString();
            region.Value = Address["Region_"].ToString();
            country.Value = Address["CountryID"].ToString();
        }

        public epicor_Organization.OrganizationFullDataSet.PhysicalAddressRow Get()
        {
            _Address["Address1"]=address1.Value;
            _Address["Address2"]= address2.Value;
            _Address["Address3"]=address3.Value ;
            _Address["City"] = city.Value;
            _Address["PostalCode"] = zip.Value;
            _Address["Region"] = region.Value;
            _Address["CountryID"] = country.Value;

            return _Address;
        }

    }
}

从父控件中调用它的Page_Load事件中的Set()函数。除我的选择之外的所有数据都已正确设置。

我的问题是我无法在Page_Load事件后设置select的值吗?我怎么能绕过这个?

1 个答案:

答案 0 :(得分:1)

我已经弄明白了。 Page_Load事件在我的Set方法之后触发。我换了Page_Init的Page_Load事件,一切都很好。