First of all, I'm new to Ajax and I don't quite understand everything about how it's work in Asp.Net.
I'm using Asp.Net 3.5 and I have a c# server code that run and when it's have finish it work, it's call a subscribed event that will write the result in a txtbox control.
c# code :
public partial class TestDBLoader : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
dbManager1.LoadDBCompleted += new DBManager.AsyncLoadDBDelegate(dbManager1_LoadDBCompleted);
dbManager1.LoadDBAsync(sender, e, null);
}
public void dbManager1_LoadDBCompleted(object sender, EventArgs e)
{
txtResult.Text = "Finish!";
updatePanel.Update();
}
}
public partial class DBManager : System.Web.UI.UserControl
{
public AsyncLoadDBDelegate asyncLoadDB;
public delegate void AsyncLoadDBDelegate(object sender, EventArgs e);
public event AsyncLoadDBDelegate LoadDBCompleted;
private void StartLoad(object sender, EventArgs e)
{
// Not the true code, only an example ...
for (int i = 0; i <= 10; i++)
{
Thread.Sleep(1000);
}
LoadDBCompleted(sender, e);
}
public IAsyncResult LoadDBAsync(object sender, EventArgs e, AsyncCallback callback)
{
IAsyncResult asyncResult;
asyncLoadDB = new AsyncLoadDBDelegate(StartLoad);
asyncResult = asyncLoadDB.BeginInvoke(sender, e, callback, null);
return asyncResult;
}
}
Asp code :
<asp:ScriptManager ID="ScriptManager" runat="server" />
<asp:UpdatePanel ID="updatePanel" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="dbManager1" EventName="LoadDBCompleted" />
</Triggers>
<ContentTemplate>
<uc:DBManager ID="dbManager1" runat="server" />
<asp:TextBox ID="txtResult" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
What am I doing wrong ? If I go in debug, i notice that my method dbManager1_LoadDBCompleted is call but it's doesn't update the textbox...
EDIT : I update the code to be more realistic and understandable.
EDIT2 : If there is a way of doing it without using the UpdatePanel, please let me know how.