2013-01-14 116 views
1

我需要VB的幫助(沒有C#或Javascript,請 - 我對這些語言無能爲力) 我也檢查了所有「可能已經有你的答案的問題 - 和那些在VB中不符合我的情況,或通過使用AutoPostback,編碼一個textChanged事件,或添加ontextchanged =到文本框字段---我已經在我的代碼中已經所有這些都解決了。儘管將AutoPostBack設置爲true,但似乎無法觸發TextChanged事件 即使創建提交按鈕後,它仍然不會觸發,我還遺漏了什麼?formview textbox控件textchanged事件不會觸發

什麼我試圖完成: 當且僅當用戶編輯開始日期時,我希望完成日期設置爲開始日期後30天的日期。否則只在結束日期顯示那裏最初顯示的任何內容。 這兩個日期都允許在數據庫中爲空,並且都被定義爲日期時間。

Default.aspx中

<asp:FormView ID="FormView1" runat="server" DataKeyNames="MASTERID_Action" 
DataSourceID="srcAction"> 
<EditItemTemplate> 
MASTERID_Action: 
<asp:Label ID="MASTERID_ActionLabel1" runat="server" 
Text='<%# Eval("MASTERID_Action") %>' /> 
<br /> 
Action_StartDate: 
<asp:TextBox ID="Action_StartDateTextBox" runat="server" 
Text='<%# Bind("Action_StartDate") %>' 
ontextchanged="Action_StartDateTextBox_TextChanged" AutoPostBack="True" />   <rjs:PopCalendar ID="StartDateCal" runat="server" Control="Action_STartDateTextBox" /> 
<br /> 
Action_FinishDate: 
<asp:TextBox ID="Action_FinishDateTextBox" runat="server" 
Text='<%# Eval("Action_FinishDate") %>' /> 
<br /> 
<asp:Button ID="SubmitButton1" runat="server" Text="Refresh" 
onclick="SubmitButton1_Click" /> 
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" 
CommandName="Update" Text="Update" /> 
&nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server" 
CausesValidation="False" CommandName="Cancel" Text="Cancel" /> 
</EditItemTemplate> 

在Default.aspx.vb

Partial Class _Default 
Inherits System.Web.UI.Page 

Protected Sub Action_StartDateTextBox_TextChanged(sender As Object, e As System.EventArgs) 
Dim txtStartDate As TextBox = Me.FormView1.FindControl("Action_StartDateTextBox") 
Dim txtFinishDate As TextBox = Me.FormView1.FindControl("Action_finishdatetextbox") 
Dim strNewFinishDate As String 

If txtFinishDate.Text = "" And txtStartDate.Text <> "" Then 
strNewFinishDate = Convert.ToString(Convert.ToDateTime(txtStartDate).AddDays(30)) 
ElseIf txtFinishDate.Text <> "" Then 
strNewFinishDate = txtFinishDate.Text 
Else 
strNewFinishDate = "" 
End If 

txtFinishDate.Text = strNewFinishDate 

End Sub 


Protected Sub SubmitButton1_Click(sender As Object, e As System.EventArgs) 
Dim mytest As String 
End Sub 
End Class 

16/01/2013編輯:曾在保護小組Action_StartDateTextBox_TextChanged一個錯字跑了網頁,但它仍然不會起火。請繼續需要幫助。

17/01/2013編輯:我的問題仍然沒有答案,我收到的響應導致更多的錯誤。請幫忙。

+0

嘗試重新啓動visual studio。有時它會產生問題... –

+0

重新啓動沒有解決問題,謝謝。 – AAllen

回答

0

對此沒有迴應,但我必須繼續前進。所以,我選擇了什麼可能是更智能的路線 - 將我的回傳作爲客戶端JavaScript來處理。我會接受「asp.net無法做到這一點的答案。Javascript會讓你的生活變得如此簡單」。對於這個問題....

0

我認爲在編寫相應的事件之後,你可能已經刪除了你的控件。如果是這樣,結果它將刪除你用事件指定的所有處理程序。

'---This is your code, by the way it seems to be missing its handler 
... Action_StartDateTextBox_TextChanged(sender As Object, e As System.EventArgs) 

嘗試添加其處理程序是這樣,

'---Adding hanler 
... Action_StartDateTextBox_TextChanged(sender As Object, e As System.EventArgs) Handles Action_StartDateTextBox.TextChanged 

如果您需要關於事件處理程序的詳細信息,只是參考this.

+0

謝謝。我試了一下,但添加了Handler子句導致了另一個錯誤,它聲明「Handles子句需要在包含類型或其基類型中定義的WithEvents變量。所以,,,,我添加了With事件並將我的Formview1我得到了BOTH:「句柄子句需要在包含類型或其基類型中定義的WithEvents變量。」AND「'formview1'已經被聲明爲'Protected WithEvents FormView1 As System 「 – AAllen

+0

不是OnTextChanged =」Action_STartDateTextBox_TextChanged「做」處理「部分? – AAllen

+0

如何重新激活此問題以獲得幫助? – AAllen

相關問題