简体   繁体   中英

Page can only have one server-side form tag

I'm facing a problem with one of my pages. I have a FormView control on the page that I use to enter new rows into a database table, and a GridView control on the same page to update/delete rows from the same database table.

The FormView control has validators on it to validate any input being thrown at the database, and it seems to interfere with the GridView when I try to edit a row. When I try to save the edit, the validation control on the FormView gets fired and an error comes up because the textbox input is blank, so the GridView cannot save the modified table data.

Perhaps a visible example will help:

屏幕截图

I had an idea where I encase these controls in different forms, hoping that the submit of one form won't fire anything in the other but then I got an error saying I can't have more than one form on the page with runat="server" , which as far as I can tell is required.

How can I get around this?

Thanks.

You can only have one Form .

Use different ValidationGroups for your FormView and GridView instead.

http://msdn.microsoft.com/en-us/library/ms227424(v=vs.100).aspx

Yes, this is a known limitation (feature?) of webforms. You can only have 1 form with a runat="server" tag.

In your scenario you can use ValidationGroup names to group validation together so only "like" validation is executed when a control of the same validation is triggered.

What I did is I had two forms coded as postback to the page and parsed out the postback variables in Page.Load myself. Weird? Yes. Works? Yes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM