0
在我的網頁中,我使用兩個用戶控件: ucControl1和ucControl2。 ucControl1控件還包含其中的ucControl2控件的一個實例。 當您運行應用程序並轉到相關頁面時,似乎只有ucControl1內部的實例才能正常工作。當試圖執行直接在頁面上的ucControl2的功能時,它會正確地執行後端代碼,正確打開模式,但不會在屏幕上顯示結果。 會發生什麼?asp.net頁面中相同用戶控件的兩個實例
的頁面是這樣
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="PageSample.aspx.cs" MasterPageFile="~/MasterPage.master" Inherits="PageSample" %>
<%@ MasterType VirtualPath="~/MasterPage.master" %>
<%@ Register Src="~/Controls/ucControl2.ascx" TagPrefix="uc2" TagName="ucControl2" %>
<%@ Register Src="~/Controls/ucControl1.ascx" TagPrefix="uc1" TagName="ucControl1" %>
<asp:Content runat="server" ContentPlaceHolder ID="cpSampleID">
<div>
<uc1:ucControl2 runat="server" ID="uc2" />
</div>
<uc1:ucControl1 runat="server" ID="uc1" />
</asp:Content>
而且的UserControl1
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ucControl1.ascx.cs" Inherits="ucControl1" %>
<%@ Register Src="~/Controls/ucControl2.ascx" TagPrefix="uc1" TagName="ucControl2" %>
<%-- Something Something Something --%>
<uc1:ucControl2 runat="server" ID="ucControl2" />
認爲我們需要看到自己的用戶控件,並且後端代碼 – ADyson
後端工作得很好。它只是在文本框中設置一些文本值。 我做了一些測試,並且頁面的ucControl字段被填充,但是看起來在渲染時總是呈現ucControl2中的ucControl1。 如果我從頁面中刪除ucControl1,完美地工作。 –
「ucControl2內部的ucControl1」。你的意思是相反的嗎?無論如何,你提供的代碼不足以發現問題。你可能認爲你的後端工作正常,但很明顯,代碼中的某些內容導致了問題,所以我們需要看到它。抽象地說,沒有理由說你所展示的設計不起作用。問題將出現在某處的實現細節中。因此,請不要基於模糊和無法驗證的「正常工作」聲明提出異議,請節省一些時間併發布代碼,以便其他人可以爲您提供有意義的幫助。 – ADyson