开发者

Is it a problem to use the same IDs in different asp.net FormView templates?

开发者 https://www.devze.com 2022-12-21 23:57 出处:网络
I understand that only one FormView template is rendered at any given time, so is it ever a problem to reuse child control IDs?

I understand that only one FormView template is rendered at any given time, so is it ever a problem to reuse child control IDs?

For example, the insert and edit templates are identical in this FormView, each has a TextBox in which a user may enter their name. Would it be a problem (or a bad idea) to give both text boxes the ID "NameTextBox"?

Better yet, is there a way I can create a single template that is used in both insert and edit modes? With the same cod开发者_运维知识库e-behind, event handlers, etc? I found a forum thread somewhere that suggested creating a web user control to use in both insert and edit modes - is this typical?


Yes, you can use the same ID in different FormView templates. This works exactly like the repeater controls which use templates.

However... there is no way that I know of to use a single template as both insert and edit modes. If you want to do that, why use a FormView at all? Just use a straight webform and handle the insert/edit logic yourself.

0

精彩评论

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