我有地址用户控制。
我在我的页面上使用了两个地址,一个用于公司地址,另一个用于邮寄地址。所以我在一个页面上使用了我的地址用户控件两次。
在这个地址用户控件中,当用户填写邮政编码时,我将从数据库中提取街道地址和建筑物地址并为用户填写文本框。
但我的问题是,每当用户填写一个邮政编码时,两个地址用户控件都会填充相同的数据。
这是我的地址用户控件示例代码
public delegate void AddressForServiceHandler(string callType, string refreshType, Dictionary<string, string> keyvalues);
public delegate void MailAddressForServiceHandler(string callType, string refreshType, Dictionary<string, string> keyvalues);
public event AddressForServiceHandler AddressForService_APICall;
public event MailAddressForServiceHandler MailAddressForService_APICall;
protected void txtPostalCode_TextChanged(object sender, EventArgs e)
{
#region delegate func
Dictionary<string, string> Params = new Dictionary<string, string>();
Params.Add("PostalCode", txtPostalCode.Text.Trim());
if (AddressForService_APICall != null)
{
AddressForService_APICall(txtPostalCode.Text, "PostalCode", Params);
}
if (MailAddressForService_APICall != null)
{
MailAddressForService_APICall(txtPostalCode.Text, "PostalCode", Params);
}
#endregion
}
txtPostalCode_TextChanged事件同时触发* AddressForService_APICall*和MailAddressForService_APICall,因此两个地址用户控件都填充了相同的数据。
我应该如何处理这种情况?我只想填充一个相应的地址用户控件。提前致谢。
凯文
更新
这是我将填充数据的代码。这是在aspx页面上的编码。
protected void InitializeEvents()
{
Address1.AddressForService_APICall += new AddressForServiceHandler(AddressForService);
Address2.MailAddressForService_APICall += new MailAddressForServiceHandler(MailAddressForService);
}
protected void AddressForService(string callType, string refreshType, Dictionary<string, string> keyvalues)
{
try
{
using (ServiceAddress cmProxy = new ServiceAddress())
{
Dictionary<string, string> dsPostalCode = new Dictionary<string, string>;
dsPostalCode = cmProxy.GetAddress(callType, refreshType, keyvalues);// it will return the dictionary filled with the data
Address1.RefreshAddressForRegistration(dsPostalCode); // here I call address control method to fill the data
}
}
catch (Exception ex)
{
...
}
}
protected void MailAddressForService(string callType, string refreshType, Dictionary<string, string> keyvalues)
{
try
{
using (ServiceAddress cmProxy = new ServiceAddress())
{
Dictionary<string, string> dsPostalCode = new Dictionary<string, string>;
dsPostalCode = cmProxy.GetAddress(callType, refreshType, keyvalues);
Address2.RefreshAddressForRegistration(dsPostalCode);
}
}
catch (Exception ex)
{
...
}
}