由于我没有编程经验,我的问题可能很愚蠢,但请帮助。
因此,我将一些文本框设置为其他页面中的值,以便用户可以编辑他们的任务并查看他们的任务是原始任务并从那里进行编辑。
问题是我在页面加载中设置了这些值,因此当我尝试更新它时,它更新了原始值而不是输入的新值,因为页面加载返回旧值。因此,我无法将数据库更新为新值。
有没有办法解决这个问题或解决这个问题?就像我应该将代码放在其他地方吗?
编辑:好的,所以我做了更多的研究,发现我的问题可以通过使用 IsPostBack 来解决,但我不明白如何使用此代码。我唯一明白的是它用于在页面加载刷新之前将页面返回到页面?
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Session("Editing") IsNot Nothing Then
btnCreate.Visible = False
btnEdit.Visible = True
Dim Form As FormViewRow = CType(Session("Editing"), FormViewRow) 'get data from the the formview in Home page
Dim Title As Label = CType(Form.FindControl("TitleLabel"), Label)
txtTitle.Text = Title.Text
Dim description As Label = CType(Form.FindControl("DescriptionLabel"), Label)
txtDescription.Text = description.Text
Dim diff As Label = CType(Form.FindControl("DifficultyLabel"), Label)
ddlDifficulty.Text = diff.Text
Dim taskID As Label = CType(Form.FindControl("IDLabel"), Label)
Dim whatID As String = taskID.Text
Session("EditTaskID") = taskID.Text
End If
End Sub
好的,所以我只是在玩 IsPostBack 并设法让它工作。
我所做的只是将我的代码放在 If 语句中 IsPostBack is not equal True Then... 由于我还在学习,有人可以用最简单的术语解释 IsPostBack 的含义吗?
如果没有人向我解释也无妨。我的问题解决了,感谢阿明花时间帮助我。(:
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If IsPostBack <> True Then
If Session("Editing") IsNot Nothing Then
btnCreate.Visible = False
btnEdit.Visible = True
Dim Form As FormViewRow = CType(Session("Editing"), FormViewRow) 'get data from the the formview in Home page
Dim Title As Label = CType(Form.FindControl("TitleLabel"), Label)
txtTitle.Text = Title.Text
Dim description As Label = CType(Form.FindControl("DescriptionLabel"), Label)
txtDescription.Text = description.Text
Dim diff As Label = CType(Form.FindControl("DifficultyLabel"), Label)
ddlDifficulty.Text = diff.Text
Dim taskID As Label = CType(Form.FindControl("IDLabel"), Label)
Dim whatID As String = taskID.Text
Session("EditTaskID") = taskID.Text
End If
End If
End Sub
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句