我有一个包含设计和代码的 ascx 页面。我想在具有不同 ID 名称的 aspx 页面中的向导控件的每个向导步骤中调用该页面。但是由于每个向导步骤的 ascx 页面中 ascx 页面的 id 都发生了变化,我需要使用不同的 ascx 页面 ID 编写相同的代码。
在 register.aspx 页面中:
<i><asp:WizardStep ID="WizardStep2" runat="server" Title="schooling">
<div class="content">
<addr:addr ID="address_acx" runat="server"/> //calling usercontrol with Id "address_ascx"
</div>
</i>
</asp:WizardStep>
并在函数后面的代码中获取值:
public string[] getASCXvalues()
{
string school_name = null, sid = null, section = null;
CheckBox chk = (CheckBox)address_acx.ID .FindControl("chk_school");
TextBox txt_school = (TextBox)address_acx.FindControl("txt_school");
if (chk.Checked || address_acx.schoolnames <= 1)
{
school_name = txt_school.Text;
sid = BAL.Class1.getmaxid() + 1;
int val = Convert.ToInt32(sid.Substring(1, 6)) + 1;
sid = sid.Substring(0, 1) + val.ToString().PadLeft(6, '0');
}
else
{
school_name = address_acx.selectedschollname;
sid = address_acx.selectedschoolcode;
}
CheckBox chk_sec = (CheckBox)address_acx.FindControl("chk_section");
TextBox txt_sec = (TextBox)address_acx.FindControl("txt_section");
if (chk_sec.Checked || address_acx.sectioncount <= 1)
{
section = txt_sec.Text;
}
else
{
section = address_acx.selectedsec;
}
string[] a = new string[10];
a[0] = address_acx.selectedyear;
a[1] = address_acx.selectedmandal;
a[2] = address_acx.selectedvillage;
a[3] = school_name;
a[4] = sid;
a[5] = section;
return a;
}
现在问题出在下一个向导步骤中,我必须使用 ascx 页面的另一个 ID 重新编写上述函数。