我是 ASP.net 的新手,我有一些关于回发的问题。
我有一个像这样的 Senario:
1)我在网络上有一个网格,里面有一个面板。
2)我通过调用此“插入”带有Web用户控件的面板
Control ctlControl;
ctlControl = LoadControl("~/UserControls/ChequeCreation.ascx");
pnlTransaction.Controls.Add(ctlControl);
3)Web用户控件提供两个按钮。一是“更新”,一是“重置”。
问题是这样的:
我想要实现的是当按下“更新”按钮时,它会将某些内容更新回我的数据库?但在我按下“更新”或“重置”按钮后似乎。 Web 用户控件消失或丢失。对于我的客人来说是因为回发问题吗?这是正确的吗?
我尝试了 if(!postback) 仍然不起作用。
我该如何克服这个问题?我已经挠头大约一天了?
非常感谢你。
问候
LiangCk:
PS:抱歉我的英语水平,请随时指出我的错误或错误。
I am new to ASP.net thing, and i have some question regarding postback.
I have a Senario like this:
1) I have a grid on web with a panel inside.
2) I "Insert" the panel with a Web User Control by calling this
Control ctlControl;
ctlControl = LoadControl("~/UserControls/ChequeCreation.ascx");
pnlTransaction.Controls.Add(ctlControl);
3)The Web User Control providing two button. One is "update" and one is "reset".
Problem is like here:
What i wanted to achieve is when press the "update" button, it will update something back to my DB? But seem after i press the button "Update" or "Reset". The web user control is gone or missing. For my guest is because of the postback issues? Is that correct?
I tried if(!postback) still its doesn't work.
How am i going to overcome this? I already scratching my head about a day?
Thanks you so much.
Regards
LiangCk:
PS:Sorry for my english level, and please dont hesitate to voice out my error or mistake.
发布评论
评论(4)
那么,您可以将任何数据列转换为模板列,然后将 Web 用户控件拖放到其中,
这将导致类似于以下代码的结果,检查“uc1:webUserControle1”在代码中的位置
well you can convert any of your data columns to template column and then drag and drop your web user control to it
this will result in something like the following code check where "uc1:webUserControle1" is located in the code
如果您使用 AJAX,请尝试在 UCT 设计页面上添加 updatepanel
if you are using AJAX, try add updatepanel on your UCT design page
ASP.NET 不会在回发之间保留动态添加的用户控件。这就是它消失的原因。每次创建页面时都需要添加该控件。但是,如果您希望触发事件,则需要在初始化控件树时添加它并恢复原始控件 ID。这些链接提供了完整的解释https://web.archive.org/web/20210330142645/http://www.4guysfromrolla.com/articles/092904-1.aspx 和 http://avinashsing.sunkur.com/2011/02/24/dynamic-controls-viewstate-and-postback/
ASP.NET will not preserve a dynamically added user control between postbacks. This is why it is dissapearing. You will need to add the control each time the page is created. However you will need to add it when the control tree is being initialized and restore the original control ID if you want your events to fire. These links provide a full explanation https://web.archive.org/web/20210330142645/http://www.4guysfromrolla.com/articles/092904-1.aspx and http://avinashsing.sunkur.com/2011/02/24/dynamic-controls-viewstate-and-postback/
您必须每次在 Page_Init 上重新加载用户控件或
页面_加载。然后你可以得到按钮点击事件和用户之后
控制权不会丢失。
You have to Every Time Reload the user control on Page_Init or
Page_Load. Then you can get the Button Click Event and After tha User
Control will not lost.