1
我有一个asp.net Web窗体,有一个更新面板,其中包含一个带有用户输入值的文本框的表格。该表位于updatepanel中,因为文本框是从运行时间很长的db查询中生成的。它使用计时器控件在表单加载后几秒钟生成。尝试从代码后面的代码中检索UpdatePanel中的值
当窗体回表不提供给我们的代码...
下面是该部分的代码,这是一个DynamicData编辑页面。
<asp:UpdateProgress ID="UpdateProgress1" runat="server"
AssociatedUpdatePanelID="UpdatePanel2">
<ProgressTemplate>
<div>Getting subjects...</div>
</ProgressTemplate>
</asp:UpdateProgress>
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional" >
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" Interval="2000" Enabled="false" >
</asp:Timer>
<div id="subjects_fav">
<asp:Table ID="tabSubjectsFav" runat="server" BorderWidth="2" BorderColor="Aquamarine">
</asp:Table>
</div>
<asp:Button ID="UpdateButton" runat="server" OnClick="SaveEverything" Text="Save Everything" />
</ContentTemplate>
</asp:UpdatePanel>
Protected Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs)
'DynamicDataManager1.RegisterControl(DetailsView1)
DynamicDataManager1.RegisterControl(lvArticles1)
DynamicDataManager1.RegisterControl(lvArticles2)
DynamicDataManager1.RegisterControl(lvArticles3)
DynamicDataManager1.RegisterControl(lvArticles4)
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
'trying to get the id_project for this page
'get article id for first article
If Not IsPostBack Then
Timer1.Enabled = True
Else
UpdatePanel2.Update()
End If
'now get related project from db
Dim db As New MTRData.mtddDataContext()
Dim art = (From a In db.articles _
Where a.id = Request.QueryString("id") Take 1 _
Select a).SingleOrDefault()
'txtid_project.Text = art.id_project
'need to use this all over the place so saving it as a property type thing as well
_ProjectID = art.id_project
_PublicationID = art.id_publication
_ArticleID = art.id
End Sub
Protected Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If boolTimerFired = False Then
Timer1.Enabled = False
boolTimerFired = True
GenerateSubjectsFavGrid(_ArticleID)
UpdatePanel2.Update()
End If
Timer1.Enabled = False
End Sub
嗨womp,谢谢你,在OnInit中没有完成,因为他们需要30秒钟将当前值从db中取出(不要问!)。所以他们在页面加载后通过一个计时器完成几秒钟...... – DaveEHS 2009-08-20 15:45:10
是的,如果“GenerateSubjectsFavGrid(_ArticleID)”是您将文本框动态添加到页面的地方,那么这就是问题所在。这里添加的任何控件都不会出现在下一个回传中创建的下一个页面对象中。网格总是一样的大小?任何使网格变为非动态的可能性,将可见性设置为false,并在完成填充时显示它? – womp 2009-08-20 17:12:17
嗨womp,可悲的是,不同客户之间会有所不同。这些值不会在response.form中吗?我想我必须将这些值保存到会话中,或者当它们通过JavaScript进行更改时,然后从那里填充值。实际上,这个对话使我想到,我可能会缓存所需的控件,然后只是担心会话中的值或什么。感谢我在广告中指出我正确的方向。干杯,戴夫。 – DaveEHS 2009-08-20 18:28:05