1
私はブートストラップアラートを使用していますが、コード内の静的メソッドからアラートクラスを変更しようとしていますが、エラーが発生しています:C#HtmlGenericControlエラー静的メソッドから
非静的フィールドにはオブジェクト参照が必要です。
イムかなり新しいこのように任意のヘルプははるかに高く評価されるだろう
aspx.csへ:
public static void alert()
{
wallboardAlert.Visible = alertVisable;
wallboardAlert.Attributes["class"] = alertClassType;
}
.aspxの
<div class="" id="wallboardAlert" runat="server">
<h1 id="wallboardAlertTitle" runat="server"><strong></strong></h1>
<h4 id="wallboardAlertBody" runat="server"></h4>
</div>
宣言から 'static'を削除するだけです。 'wallboardAlert'はあなたのページクラスで定義されており、インスタンスメソッドからアクセスする必要があります。 –
またはhttp://stackoverflow.com/questions/14684974/asp-net-access-a-control-from-static-function –
私は宣言から静的メソッドを呼び出すクラスは、動作しません – user3362804