【问题标题】:calling ascx page in aspx with differnt ID names用不同的 ID 名称在 aspx 中调用 ascx 页面
【发布时间】:2013-03-18 06:44:55
【问题描述】:

我有一个包含设计和代码的 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 重新编写上述函数。

【问题讨论】:

    标签: asp.net


    【解决方案1】:

    您可以通过发送用户控件(ascx)作为函数的参数来解决您的问题。

    public string[] getASCXvalues(UserControl addressControl)
    {
            string school_name = null, sid = null, section = null;
            CheckBox chk = (CheckBox)addressControl.FindControl("chk_school");
            TextBox txt_school = (TextBox)addressControl.FindControl("txt_school");
    }
    

    【讨论】:

    • 我已经试过了。如果我将 usercontrol 作为参数传递,它会显示错误,因为 ascx 页面包含获取一些在 aspx 页面中使用的值的属性
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多