开发者

Get Value from Dynamic User Control On PostBack Asp.Net

I created an item user_control that has a textbox, button, etc. which will intentionally collect the total quantity of items the user wants.

I dynamically create开发者_如何学运维 a few intances of user_control on page_load. If you click the add button for the item quantity it will add to a session variable. however when the user enters a different quantity in the textbox and clicks the add button the total is of the original value of the textbox.

How to get the value the the user has typed in to the textbox to add to total???


You need to assign the same ID to the dynamic control after each postback, when you recreate the control. If you don't assign it the same ID, ViewState cannot populate the value.

protected override void OnInit(EventArgs e)
{
    base.OnInit(e);

    TextBox txt = new TextBox();
    txt.ID = "txt1"; 

    PlaceHolder1.Controls.Add(txt);            
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜