【问题标题】:formview textbox control textchanged event will not fireformview 文本框控件 textchanged 事件不会触发
【发布时间】: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" />
&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 编辑:我的问题仍未得到解答,我收到的回复导致更多错误。请帮忙。

【问题讨论】:

  • 尝试重新启动视觉工作室。有时它会产生问题......
  • 重启没有解决问题,谢谢。

标签: asp.net vb.net autopostback


【解决方案1】:

我认为您可能在编写相应事件后删除了您的控件。如果是这样,结果它将删除您为事件指定的所有处理程序。

'---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.

【讨论】:

  • 谢谢。我试了一下,但添加 Handler 子句导致另一个错误,指出“Handles 子句需要在包含类型或其基本类型之一中定义的 WithEvents 变量。所以,,,,我添加了一个 With 事件并在我的 Formview1 中删除类并得到了一组完全虚伪的错误。我得到了两个:“Handles 子句需要在包含类型或其基类型之一中定义的 WithEvents 变量。”并且“'formview1'已经声明为'Protected WithEvents FormView1 As System .Web.UI.WebControls.FormView' 在这个类中。”
  • OnTextChanged="Action_STartDateTextBox_TextChanged" 不做“处理”部分吗?
  • 如何重新激活此问题以获得帮助?
  • @AAllen 看看这个link
【解决方案2】:

对此没有回应,但我必须继续前进。因此,我选择了可​​能更聪明的方法——将我的回发作为客户端 javascript 来处理。对于这个问题,我会接受“asp.net 无法做到这一点。Javascript 会让你的生活变得如此轻松”的答案......

【讨论】:

    猜你喜欢
    • 2015-07-26
    • 2012-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-28
    • 1970-01-01
    相关资源
    最近更新 更多