【发布时间】:2013-01-14 04:44:49
【问题描述】:
我需要 VB 方面的帮助(请不要使用 C# 或 Javascript ——我对这些语言一无所知) 我还检查了所有“可能已经有你答案的问题——那些在 VB 中的问题与我的情况不匹配,或者通过使用 AutoPostback、编码 textChanged 事件或将 ontextchanged= 添加到文本框字段来解决—— - 我的代码中已经有了所有这些。
尽管将 AutoPostBack 设置为 true,但我似乎无法触发 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" />
<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 编辑:我的问题仍未得到解答,我收到的回复导致更多错误。请帮忙。
【问题讨论】:
-
尝试重新启动视觉工作室。有时它会产生问题......
-
重启没有解决问题,谢谢。
标签: asp.net vb.net autopostback