2017-09-01 39 views
1

這是我的拳頭問題,我一直在尋找如何使用複選框在ac#web窗體中,我發現一些代碼幾乎是我所需要的,但我不斷得到錯誤,因爲所有這些代碼都不適用於C#Web表單。Visual Studio C#web窗體複選框CheckedChanged方法錯誤

File.aspx有這樣的代碼:

<asp:CheckBox ID="cbxScheduleDate" runat="server" Text="Schedule for today" AutoPostBack="true"; OnCheckedChanged="cbxScheduleDate_CheckedChanged"/> 

File.aspx.cs有這樣的代碼:

protected void cbxScheduleDate_CheckedChanged(object sender, EventArgs e) 
    { 
     if (cbxScheduleDate.Checked) 
      txtScheduleDate.Visible = false; 
     else 
      txtScheduleDate.Visible = true; 

    } 

所以,當複選框被選中我做txtScheduleDate文本框我需要的是不可見。

現在與該代碼,Visual Studio中有錯誤:

The name 'cbxScheduleDate' does not exist in the current context

現在有沒有人如何解決這個Visual Studio的錯誤,或者另一種方式來完成這項工作?

謝謝!

回答

0

您的asp標籤格式不正確。在那裏有一個分號

autopostback="true" 

這是不需要的。 OMG!

+0

OMG!對我感到羞恥...是的,你是完全正確的。我剛剛刪除了它,它現在正在工作。也許長時間處理相同的問題會讓你的大腦看不到東西。謝謝!!! – wgrando