gpt4 book ai didi

asp.net - textbox.text 更改后仍保留旧值

转载 作者:行者123 更新时间:2023-12-04 17:11:14 26 4
gpt4 key购买 nike

我有一个 asp.net 网页,其中包含一系列文本框和复选框,当页面加载时,这些文本框和复选框会填充数据库中的数据。我打算让用户可以自由更改文本或检查框的值,然后按下按钮。按下按钮后,信息将从他们编辑的框中拉出,然后数据库将根据所做的更改进行更新。问题是,即使复选框 val 的文本已更改, textbox.text 和 checkbox.checked 仍包含最初在页面加载子中加载到其中的值。

到目前为止,这是我的代码:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim lq2 As New lqDFDataContext
Dim var = lq2.admin_GetFeatured().ToList()
Dim i As Integer = 1

For Each f In var
If i = 1 Then
isChanged.featuredID1 = f.featuredID
title1.Text = f.title
text1.Text = f.text
imageURL1.Text = f.imageURL
login1.Checked = f.loginPage
index1.Checked = f.indexPage
mobile1.Checked = f.mobilePage
priority1.Text = Str(f.priority)
End If

If i = 2 Then
isChanged.featuredID2 = f.featuredID
title2.Text = f.title
text2.Text = f.text
imageURL2.Text = f.imageURL
login2.Checked = f.loginPage
index2.Checked = f.indexPage
mobile2.Checked = f.mobilePage
priority2.Text = Str(f.priority)
End If

If i = 3 Then
isChanged.featuredID3 = f.featuredID
title3.Text = f.title
text3.Text = f.text
imageURL3.Text = f.imageURL
login3.Checked = f.loginPage
index3.Checked = f.indexPage
mobile3.Checked = f.mobilePage
priority3.Text = Str(f.priority)
End If

If i = 4 Then
isChanged.featuredID4 = f.featuredID
title4.Text = f.title
text4.Text = f.text
imageURL4.Text = f.imageURL
login4.Checked = f.loginPage
index4.Checked = f.indexPage
mobile4.Checked = f.mobilePage
priority4.Text = Str(f.priority)
End If

If i = 5 Then
isChanged.featuredID5 = f.featuredID
title5.Text = f.title
text5.Text = f.text
imageURL5.Text = f.imageURL
login5.Checked = f.loginPage
index5.Checked = f.indexPage
mobile5.Checked = f.mobilePage
priority5.Text = Str(f.priority)
End If

If i = 6 Then
isChanged.featuredID6 = f.featuredID
title6.Text = f.title
text6.Text = f.text
imageURL6.Text = f.imageURL
login6.Checked = f.loginPage
index6.Checked = f.indexPage
mobile6.Checked = f.mobilePage
priority6.Text = Str(f.priority)
End If

i = i + 1


Next
End Sub

Protected Sub featuredSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles featuredSubmit.Click
Dim lq As New lqDFDataContext



If isChanged1.Checked Then
lq.admin_RemoveFeatured(isChanged.featuredID1)
lq.admin_AddFeatured(title1.Text, text1.Text, imageURL1.Text, login1.Checked, index1.Checked, mobile1.Checked, Integer.Parse(priority1.Text))

End If

If isChanged2.Checked Then
lq.admin_RemoveFeatured(isChanged.featuredID2)
lq.admin_AddFeatured(title2.Text, text2.Text, imageURL2.Text, login2.Checked, index2.Checked, mobile2.Checked, Integer.Parse(priority2.Text))

End If

If isChanged3.Checked Then
lq.admin_RemoveFeatured(isChanged.featuredID3)
lq.admin_AddFeatured(title3.Text, text3.Text, imageURL3.Text, login3.Checked, index3.Checked, mobile3.Checked, Integer.Parse(priority3.Text))

End If

If isChanged4.Checked Then
lq.admin_RemoveFeatured(isChanged.featuredID4)
lq.admin_AddFeatured(title4.Text, text4.Text, imageURL4.Text, login4.Checked, index4.Checked, mobile4.Checked, Integer.Parse(priority4.Text))

End If

If isChanged5.Checked Then
lq.admin_RemoveFeatured(isChanged.featuredID5)
lq.admin_AddFeatured(title5.Text, text5.Text, imageURL5.Text, login5.Checked, index5.Checked, mobile5.Checked, Integer.Parse(priority5.Text))

End If

If isChanged6.Checked Then
lq.admin_RemoveFeatured(isChanged.featuredID6)
lq.admin_AddFeatured(title6.Text, text6.Text, imageURL6.Text, login6.Checked, index6.Checked, mobile6.Checked, Integer.Parse(priority6.Text))

End If

End Sub


End Class

Public Module isChanged
Public featuredID1 As Integer
Public featuredID2 As Integer
Public featuredID3 As Integer
Public featuredID4 As Integer
Public featuredID5 As Integer
Public featuredID6 As Integer
End Module

最佳答案

您的 load 语句在每个页面回发时设置表单的值,它可能会覆盖原始值;您需要将 foreach 代码包装在 If (Not Page.IsPostBack) Then .. End If 中陈述。

HTH

关于asp.net - textbox.text 更改后仍保留旧值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12324287/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com