0
我有一個簡單的網頁控件,它的工作原理有點類似。它只是不允許(沒有錯誤)設置控件中的任何變量,無論我嘗試什麼,它只是不顯示除默認值之外的任何內容。簡單的網頁控件無法正確呈現
我的控制:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Message.ascx.cs" Inherits="Message" %>
<asp:Panel runat="server" ID="ErrorPanel">
<asp:Literal
runat="server"
ID="MessageTextLit"
/>
</asp:Panel>
/// <summary>
/// The type of the message, good, bad etc.
/// </summary>
public enum MessageType
{
Good,
Error
}
public partial class Message : System.Web.UI.UserControl
{
public string MessageText { get; set; } // Text of the error message
public MessageType Type { get; set; } // Message type
protected void Page_Load(object sender, EventArgs e)
{
MessageTextLit.Text = MessageText;
// Set correct CSS class
if (Type == MessageType.Good)
ErrorPanel.CssClass = "good-box";
else if (Type == MessageType.Error)
ErrorPanel.CssClass = "bad-box";
}
}
在我的網頁我有它:
<CrystalControls:Message runat="server" ID="TopMessage" Visible="false" />
然後,當按下按鈕,我做的:
if (QuestionSubject.Length < 5)
{
TopMessage.MessageText = "Soemthing message";
TopMessage.Type = MessageType.Error;
TopMessage.Visible = true;
}
else if (QuestionBody.Length < 10)
{
TopMessage.MessageText = "Error message";
TopMessage.Type = MessageType.Error;
TopMessage.Visible = true;
}
我檢查,並且如果正在發射,它不會拋出任何錯誤,但Message
類中的變量都不會設置!他們只是默認我做的任何事情。我無法改變他們的任何價值觀。
Brilliant this works thanks – 2011-04-11 11:10:57