简体   繁体   中英

Problem with controls dissapearing in ASP.NET Webforms

I'm really new to ASP.NET webforms. Currently I was trying to change some code on a page: I had a modal that had several tabs in it. The idea was to move the content of two of those tabs into a popup (which is also another modal itself) that shows up when you press a button. That code was done and, when, for a moment, I had the same code replicated (I kept the tabs in the modal AND also had the button showed a popup with the same two tabs within, meaning that both old and new code were coexisting at the same time), the popup worked pefectly fine and as expected. How I got it to work was simply creating a new modal, and copying and pasting the original code inside two tabs inside a tab-panel, average stuff. However, once I finally deleted the OLD code, the whole thing stopped working. All controls in the code I copy-pasted stopped working; they where deleted from the designer. If I set back the changes in the designer, basically forcing the code for the controls back into existence, the errors will dissapear and the code will run, but everything will be set to null, and the page will not load.

My new code is still in the same html file, within the same content div, but for some reason that I am too much of a newbie to understand, it just won't locate the controls. Here a snippet of my html code:

<asp:RequiredFieldValidator ID="RequiredFieldValidator3" Display="Dynamic" ValidationGroup="PaymentTermsForm" runat="server" ControlToValidate="ddlPayeeTerms" InitialValue="0" SetFocusOnError="true" ErrorMessage="Payee Terms is required" CssClass="required-field-validator-information"></asp:RequiredFieldValidator>

The ddlPayeeTerms control is missing altogether; same with every other element that got copied and pasted. All the content of the code is within this tags:

<asp:UpdatePanel runat="server" ID="UpdatePanel1" UpdateMode="Conditional">
                                            <ContentTemplate>

I don't really know enough of webforms to know if that fact is relevant, so I just add it just in case.

I really could use a hand understanding what and why is going on, and if there is a way to solve this? Thanks in advance guys.

It is hard to answer this without seeing everything that is happening, including the errors you got when you deleted it.

Taking into account that your control has runat="server", you probably have code associated with the controls in the backend (cs file that is behind the aspx file). Obviously deleting those controls without modifying the code behind would result in errors and would not work. The code behind reads the control using ID, so they all have to be unique.

If you can give me the errors you get after deleting the controls, I might be able to help you a little more.

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