ASP.NET Label Inside UpdatePanel Not Updating
I am new to ASP.NET and I'm trying to get a Label to update with some information that is grabbed when I hit a button. The click function is called and returns just fine (I've debugged and stepped through the whole thing). The only thing that doesn't work is where I set the text of the Labels I'm trying to update.
This is the function that gets called on the button click:
Protected Sub submitbutton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles submitbutton.Click
Dim res As String() = query(email1.Text)
If Not res Is Nothing Then
url1.Text = res(0)
date1.Text = res(1)
End If
End Sub
I know it goes into the if and tries to set the text but nothing happens on the client side.
This is the UpdatePanel I have:
<asp:UpdatePanel ID="UpdatePanelSettings" runat="server" UpdateMode="Always" >
<Triggers>
<asp:AsyncPostBackTrigger ControlID="submitbutton" EventName="click" />
</Triggers>
<ContentTemplate>
<table>
<tr>
<td>Emails</td><td>Url Parsed</td><td>Date Created</td>
</tr>
<tr>
<td>
<asp:TextBox runat="server" ID="email1" Width="300" />
</td>
<td>
<asp:Label runat="server" ID="url1" Text="-" />
</td>
<td>
<asp:Label runat="server" ID="date1" Text="-" />
</td>
</tr>
<tr>
<td colspan="3"><asp:Button ID="submitbutton" runat="server" Text="Submit" /></td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
As I said, I know the trigger works because I've stepped through the code when it is called. I know that you also need a ScriptManager, which I have right ins开发者_Go百科ide the form element that comes in the Site.Master file (I really just stuck stuff in the default template. It's just a proof of concept project).
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
From all the articles I've found on the web, this should be all I need. One article mentioned having to do things with the Web.Config, but it said that for VS 2005 and I'm using 2010. It mentioned you didn't have to change anything in 2008, so I figured the same was true for 2010. What am I missing that I need to get the labels to update?
I haven't worked with this for a while, but you may need to explicitly call:
UpdatePanelSettings.Update()
At the end of your command.
.
Give it a try anyway.
Can you try removing the section.
<Triggers>
<asp:AsyncPostBackTrigger ControlID="submitbutton" EventName="click" />
</Triggers>
Then change the UpdatePanel by add ChildrenAsTriggers="true" to it.
<asp:UpdatePanel ID="UpdatePanelSettings" runat="server" UpdateMode="Always" ChildrenAsTriggers="true" >
In theory, this should be exactly the same as the way you have it above, but just trying to help you debug it.
1) Is it possible res is two blank items?
2) Is there any other code that touches the two labels (like when the form loads)?
精彩评论