Элементы пользовательского интерфейса файлов ASP.NET Sibling ASCX нельзя ссылать друг на друга в разделе кода JavaScript, поскольку они не распознаны. - PullRequest
0 голосов
/ 07 октября 2019

Вот информация о нашей среде разработки:

- .NET Framework 4

-Visual Studio 2010

-ASP.NET Web Forms

Допустим, у нас есть пользовательский элемент управления MainUserControl.ascx, который ссылается на следующие 2 пользовательских элемента управления ASCX:

-HeaderConfig.ascx

-PriceEntries.ascx

<%@ Register Src="HeaderConfig.ascx" TagName="HeaderConfig"
    TagPrefix="uc1" %>
<%@ Register Src="PriceEntries.ascx" TagName="PriceEntries"
    TagPrefix="uc2" %>

                            <uc1:HeaderConfig ID="HeaderConfig1" ShowUserDefinedFields="true"
                                IdLabel="Transaction No" ReadOnlyUserField="true" ScreenType="Redemption" ReadOnlyAmountField="true"
ReadOnlyDateField="true" BoldLabels="true" UniqueClientID="HeaderConfig1"
                                runat="server" />

                                <telerik:RadPageView ID="_pageAdditionalCharges" runat="server">
                                    <uc2:PriceEntries ID="PriceEntries1" ScreenType="Redemption"
                                        UniqueClientID="PriceEntries1" runat="server" />
                                </telerik:RadPageView>

Пользовательский элемент управления HeaderConfig.ascx содержит следующий скрытый тег ввода html:

 <input id="_hdnIsProductSoldInEuroZone" runat="server" type="hidden" value="" />

Файл записи формы пользовательского элемента управления PriceEntries.ascx содержит следующее:

<tr>
                        <td style="white-space: nowrap;">
                <asp:CheckBox ID="_chIsEuroZonePriceSpecifiedCheckBox" Text="Strike Price" runat="server" />
            </td>
            <td style="white-space: nowrap; text-align: right;">
                <label id="_lblEuroZonePriceSpecifiedCheckBoxLabel" runat="server">% :</label>
            </td>
            <td>
                <telerik:RadNumericTextBox ID="_txtEuroZonePriceRadNumericTextBox" Width="100%" MinValue="0" MaxValue="100" MaxLength="3"
                    runat="server">
                    <NumberFormat  GroupSeparator="" DecimalDigits="0" />

                </telerik:RadNumericTextBox>
            </td>

Внутри пользователя HeaderConfig.ascx. Контрольный файл, я написал следующий код Javascript:

if (document.getElementById('<%= _hdnIsProductSoldInEuroZone.ClientID %>').value == true) {
   document.getElementById('<%=_chIsEuroZonePriceSpecifiedCheckBox.ClientID %>').disabled = true;
   document.getElementById('<%=_txtEuroZonePriceRadNumericTextBox.ClientID %>').disabled = true;
}
else{
    document.getElementById('<%=_chIsStrikePriceSpecifiedCheckBox.ClientID %>').disabled = false;
   document.getElementById('<%=_txtStrikePriceRadNumericTextBox.ClientID %>').disabled = false;
}

К сожалению, я получаю следующую ошибку:

Server Error in '/' Application.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0103: The name '_chIsEuroZonePriceSpecifiedCheckBox' does not exist in the current context

Может кто-нибудь сказать, пожалуйста, как провести рефакторинг / модификацию вышеупомянутогокод, чтобы код в каждом из соответствующих файлов ascx мог ссылаться на элементы пользовательского интерфейса в другом?

...