我有一个asp.net网页,其中包含一系列文本框和复选框,当页面加载时,这些文本框和复选框会填充来自数据库的数据。我打算让用户可以自由更改文本或复选框的值,然后按下按钮。按下按钮后,信息将从他们编辑的框中拉出,然后数据库将根据所做的更改进行更新。问题是,textbox.text和checkbox.checked仍然包含最初在页面加载子程序中加载到它们中的值,即使checkboxval的文本已经更改。
下面是我的代码:
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
3条答案
按热度按时间ar5n3qh51#
load语句在每个页面回发时设置窗体的值,它可能覆盖了原始值;您需要将foreach代码 Package 在
If (Not Page.IsPostBack) Then .. End If
语句中。iyfamqjs2#
将页面加载代码放入if(!Page.IsPostback)
kmynzznz3#
您必须尝试在您的页面加载,
为了在发布数据时不刷新