所以,为了得到答案,这是我的 Page.Load 上的代码(用于测试)
你可以看到 txtBoxStarTime.Text 没有价值
对于我的情况,我在更新面板中有这个:
<asp:TextBox runat="server" ID="txtBoxStartTime" TextMode="Time" Width="102px"></asp:TextBox>
<asp:TextBox runat="server" ID="txtBoxEndTime" TextMode="Time" Width="102px"></asp:TextBox>
<asp:Button CssClass="positive" ID="btnOtherSendRequest" runat="server" Text=" Send Request" ToolTip="The selected request would be sent to X" OnClick="btnOtherSendRequest_Click"/>
这是VB.NET中的代码:
Protected Sub btnOtherSendRequest_Click(sender As Object, e As EventArgs)
Try
lblSubmitted.Text = ""
lblValidateNotInfo.Text = ""
hdnRequestType.Value = "OTH"
Dim messageSuccessful As String = "Thank you for submitting your Request(s)!"
Dim messageUnSuccessful As String = "The Request was not submitted due to some errors. Please 'Go Back' and re-send!"
Select Case ddlRequest.SelectedValue
Case "18" ' Schedule Update Call
If Not (txtBoxStartDate.Text.Length > 0 And txtBoxEndDate.Text.Length > 0 And IsDate(txtBoxStartDate.Text) And IsDate(txtBoxEndDate.Text)) Then
' AI - if dates are in invalid format
ScriptManager.RegisterStartupScript(Me, Me.GetType, "AlertScript", "alert ('Please make sure the dates are in a valid format!');", True)
Exit Sub
ElseIf Not CDate(txtBoxStartDate.Text).CompareTo(Date.Now) > 0 Then
' AI - Start Date must be greater than today.
ScriptManager.RegisterStartupScript(Me, Me.GetType, "AlertScript", "alert ('""Start"" date must be a future date!');", True)
Exit Sub
ElseIf Not CDate(txtBoxEndDate.Text).CompareTo(CDate(txtBoxStartDate.Text)) >= 0 Then
' AI - Start Date must be greater than today.
ScriptManager.RegisterStartupScript(Me, Me.GetType, "AlertScript", "alert ('""End"" date must be the same as the ""Start"" date or a date after the ""Start"" date!');", True)
Exit Sub
ElseIf CDate(txtBoxStartDate.Text).DayOfWeek = DayOfWeek.Saturday Or CDate(txtBoxStartDate.Text).DayOfWeek = DayOfWeek.Sunday Or CDate(txtBoxEndDate.Text).DayOfWeek = DayOfWeek.Saturday Or CDate(txtBoxEndDate.Text).DayOfWeek = DayOfWeek.Sunday Then
ScriptManager.RegisterStartupScript(Me, Me.GetType, "AlertScript", "alert ('Weekends excluded!');", True)
Exit Sub
Else
lblSubmitted.Text = messageSuccessful
End If
Case "19" ' Request Training Call
Case "20" ' Request Call from Cust. Service
Case "21" ' Other Request
If txtBoxOther.Text <> "" Then
lblSubmitted.Text = messageSuccessful
Else
lblSubmitted.Text = messageUnSuccessful
ScriptManager.RegisterStartupScript(Me, Me.GetType, "AlertScript", "alert ('Please enter your request into the textarea first!');", True)
txtBoxOther.Focus()
Exit Sub
End If
End Select
Call sendRequest()
Call JSEffect(True)
Catch ex As Exception
lblMessage.Text = "Error when taking the request to be inserted - " & ex.Message
Finally
hlServCenterPend.Text = "Pending Requests (" & getServCenterStatus("PEND").ToString & ")"
hlServCenterComp.Text = "Completed Requests (" & getServCenterStatus("COMP").ToString & ")"
End Try
End Sub
在这里我得到了错误:
Public Sub sendRequest(Optional pid As Integer = 0, Optional claim As Integer = 0, Optional insured As Integer = 0)
Dim req As New cls_services.request
Try
req.clinicID = CInt(MyMod.FetchStoredData("ClinicID"))
req.pid = pid
req.type = CInt(ddlRequest.SelectedValue)
Select Case req.type
Case 1, 11, 12, 13, 14
req.status = "COMP"
Case Else
req.status = "PEND"
End Select
req.claimID = claim
req.insuranceID = insured
req.dueDate = req.getDueDate(req.type)
req.other = Trim(txtBoxOther.Text)
Select Case req.type
Case 18
req.fromDate = CDate(txtBoxStartDate.Text)
req.fromTime = CDate(txtBoxStartTime.Text)//ERROR HERE! - EXCEPTION
req.toDate = CDate(txtBoxEndDate.Text)
req.toTime = CDate(txtBoxEndTime.Text)
End Select
req.fax = Trim(txtFaxTreatmentRecords.Text)
req.createUser = Request.ServerVariables("AUTH_USER")
我在这里的解决方案是尝试将文本框中的值存储在隐藏字段中,然后在代码隐藏中访问...但它仍然是“最后的措施”解决方案。
事实是,正如我所说的 - 在 PostBack 上 - “文本”值消失了。不知道为什么。
仍在等待建议! :)