문제

I need help in VB (no C# or Javascript, please -- I'm clueless with those languages) I have also checked all the "questions that may already have your answer -- and those that were in VB didn't match my situation or were resolved by using AutoPostback,coding a textChanged event, or adding ontextchanged= to the textbox field --- I have all of these in my code already.

I can't seem to get the TextChanged event to fire despite setting the AutoPostBack to true. Even after creating at submit button it still won't fire, what have I left out?

What I'm trying to accomplish: I want the Finish Date to set to a date 30 days after the Start Date if and only if the user edits a start date. Otherwise just display in the Finish Date whatever would have originally displayed there. Both dates are allowed to be null in the database and both are defined as datetime.

In 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>

In 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 edit: had a typo in Protected Sub Action_StartDateTextBox_TextChanged ran the page but it still doesn't fire. Still need help with this, please.

17/01/2013 edit: My question is still unanswered, the response I did receive caused more errors. Please help.

도움이 되었습니까?

해결책 2

No response on this, but I have to keep moving. So, I have chosen what is probably the smarter route -- to take care of my postbacks as client-side javascript. I would have accepted an answer of "asp.net can't do this. Javascript would make your life so much easier" for this issue....

다른 팁

I think you might have been deleted your controls after writing its corresponding events.If so, as a result it will remove all the handlers that you had specified with the events.

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

try to add its handler like this,

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

If you need more details regarding Event Handler, Just refer this.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top