2013-01-14 118 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

相关问题