0

lnkcat是类别的lnksubcat链接按钮,是子类别的链接按钮:

我的问题是当我点击lnk_cat相应的标签和文本框将被显示......但我点击下一个 lnk 子猫将被删除......我想将这些文本框对应的标签放在占位符上,直到我点击提交:

protected void lnkCat_Click(object sender, EventArgs e)

{    
    //Panel2.Visible = false;
    //Panel1.Visible = true;
    Label lblCat = new Label();
    lblCat.Text = "Enter new Category: ";
    PHcat.Controls.Add(lblCat);

    txtCat = new TextBox();
    _Cat = txtCat.Text;
    PhtxtCat.Controls.Add(txtCat);
    Session["Dynalbl"] = lblCat;
    Session["Dynatxt"] = txtCat;
}

protected void lnkSubCat_Click(object sender, EventArgs e)
{
    //Panel1.Visible = true;
    //Panel2.Visible = true;

    Label lblSubcat = new Label();
    lblSubcat.Text =  "Enter new Sub-Category: ";
    PHsubCat.Controls.Add(lblSubcat);

    txtSubCat = new TextBox();
    _SubCat = txtSubCat.Text;
    PhtxtSubCat.Controls.Add(txtSubCat);
}

任何人都可以建议解决这个问题吗?请!!

谢谢...

4

1 回答 1

0

你怎么看待这件事?

Label lblCat;
    Label lblSubcat;
    TextBox txtCat, txtSubCat;
    protected void lnkCat_Click(object sender, EventArgs e)
    {
        //Panel2.Visible = false;
        //Panel1.Visible = true;
        Label lblCat = new Label();
        lblCat.Text = "Enter new Category: ";
        PHcat.Controls.Add(lblCat);

        txtCat = new TextBox();
        _Cat = txtCat.Text;
        PhtxtCat.Controls.Add(txtCat);
        Session["Dynalbl"] = lblCat;
        Session["Dynatxt"] = txtCat;
    }

    protected void lnkSubCat_Click(object sender, EventArgs e)
    {
        //Panel1.Visible = true;
        //Panel2.Visible = true;
        lblCat = (Label)Session["Dynalbl"];
        txtCat = (TextBox)Session["Dynatax"];
        PHsubCat.Controls.Add(lblCat);
        PHsubCat.Controls.Add(txtCat);

        Label lblSubcat = new Label();
        lblSubcat.Text = "Enter new Sub-Category: ";
        PHsubCat.Controls.Add(lblSubcat);

        txtSubCat = new TextBox();
        _SubCat = txtSubCat.Text;
        PhtxtSubCat.Controls.Add(txtSubCat);
    }
于 2013-07-12T19:47:28.550 回答