467,915 Members | 1,084 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,915 developers. It's quick & easy.

Basic Ajax Help

Hello All, I am new to ajax and wanted to start by trying something simple.
I have a web form with an updatepanel and then inside the update panel I
have a listbox. Then outside of the updatepanel I have a button. In my
buttons click event in the cs / code behind, I have a loop that just inserts
items in the listbox. My question is, once I click the button and the loop
begins, how do I get it to update the listbox? Does this make since?
Basically, this kind of mimics a update page I plan on doing next.
TIA
Oct 10 '07 #1
  • viewed: 1507
Share:
7 Replies
You don't have to do anything it updates by itself. hence the updatepanel.
"MikeB" <m@nospam.comwrote in message
news:OX*************@TK2MSFTNGP06.phx.gbl...
Hello All, I am new to ajax and wanted to start by trying something
simple. I have a web form with an updatepanel and then inside the update
panel I have a listbox. Then outside of the updatepanel I have a button.
In my buttons click event in the cs / code behind, I have a loop that just
inserts items in the listbox. My question is, once I click the button and
the loop begins, how do I get it to update the listbox? Does this make
since? Basically, this kind of mimics a update page I plan on doing next.
TIA

Oct 10 '07 #2
That is what I though however, it is not updating. I must be missing
something. Here is my code behind:

protected void Button1_Click(object sender, EventArgs e)
{

Thread firstThread = new Thread(new ThreadStart(Coundown));
firstThread.Start();
}

public void Coundown()
{
for (int i = 0; i < 100; i++)
{

ListBox1.Items.Add(i.ToString());
Thread.Sleep(250);
}
}

Here is my aspx page:

<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:ListBox ID="ListBox1" runat="server"
Width="498px"></asp:ListBox>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ListBox1"
EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
</div>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="Button" />
</form>
"IfThenElse" <sq**********@hotmail.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
You don't have to do anything it updates by itself. hence the updatepanel.
"MikeB" <m@nospam.comwrote in message
news:OX*************@TK2MSFTNGP06.phx.gbl...
>Hello All, I am new to ajax and wanted to start by trying something
simple. I have a web form with an updatepanel and then inside the update
panel I have a listbox. Then outside of the updatepanel I have a button.
In my buttons click event in the cs / code behind, I have a loop that
just inserts items in the listbox. My question is, once I click the
button and the loop begins, how do I get it to update the listbox? Does
this make since? Basically, this kind of mimics a update page I plan on
doing next.
TIA


Oct 11 '07 #3
This will not update until the end. the browser has to get something back.

"MikeB" <m@nospam.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
That is what I though however, it is not updating. I must be missing
something. Here is my code behind:

protected void Button1_Click(object sender, EventArgs e)
{

Thread firstThread = new Thread(new ThreadStart(Coundown));
firstThread.Start();
}

public void Coundown()
{
for (int i = 0; i < 100; i++)
{

ListBox1.Items.Add(i.ToString());
Thread.Sleep(250);
}
}

Here is my aspx page:

<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:ListBox ID="ListBox1" runat="server"
Width="498px"></asp:ListBox>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ListBox1"
EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
</div>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="Button" />
</form>
"IfThenElse" <sq**********@hotmail.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>You don't have to do anything it updates by itself. hence the
updatepanel.
"MikeB" <m@nospam.comwrote in message
news:OX*************@TK2MSFTNGP06.phx.gbl...
>>Hello All, I am new to ajax and wanted to start by trying something
simple. I have a web form with an updatepanel and then inside the update
panel I have a listbox. Then outside of the updatepanel I have a
button. In my buttons click event in the cs / code behind, I have a loop
that just inserts items in the listbox. My question is, once I click
the button and the loop begins, how do I get it to update the listbox?
Does this make since? Basically, this kind of mimics a update page I
plan on doing next.
TIA



Oct 11 '07 #4
Using AJAX, am I able to update the listbox as it is updated?

"IfThenElse" <sq**********@hotmail.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
This will not update until the end. the browser has to get something
back.

"MikeB" <m@nospam.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>That is what I though however, it is not updating. I must be missing
something. Here is my code behind:

protected void Button1_Click(object sender, EventArgs e)
{

Thread firstThread = new Thread(new ThreadStart(Coundown));
firstThread.Start();
}

public void Coundown()
{
for (int i = 0; i < 100; i++)
{

ListBox1.Items.Add(i.ToString());
Thread.Sleep(250);
}
}

Here is my aspx page:

<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:ListBox ID="ListBox1" runat="server"
Width="498px"></asp:ListBox>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ListBox1"
EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
</div>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="Button" />
</form>
"IfThenElse" <sq**********@hotmail.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>>You don't have to do anything it updates by itself. hence the
updatepanel.
"MikeB" <m@nospam.comwrote in message
news:OX*************@TK2MSFTNGP06.phx.gbl...
Hello All, I am new to ajax and wanted to start by trying something
simple. I have a web form with an updatepanel and then inside the
update panel I have a listbox. Then outside of the updatepanel I have
a button. In my buttons click event in the cs / code behind, I have a
loop that just inserts items in the listbox. My question is, once I
click the button and the loop begins, how do I get it to update the
listbox? Does this make since? Basically, this kind of mimics a update
page I plan on doing next.
TIA



Oct 11 '07 #5
Your thread does not end to send anything back??
"MikeB" <m@nospam.comwrote in message
news:eU**************@TK2MSFTNGP06.phx.gbl...
Using AJAX, am I able to update the listbox as it is updated?

"IfThenElse" <sq**********@hotmail.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
>This will not update until the end. the browser has to get something
back.

"MikeB" <m@nospam.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>>That is what I though however, it is not updating. I must be missing
something. Here is my code behind:

protected void Button1_Click(object sender, EventArgs e)
{

Thread firstThread = new Thread(new ThreadStart(Coundown));
firstThread.Start();
}

public void Coundown()
{
for (int i = 0; i < 100; i++)
{

ListBox1.Items.Add(i.ToString());
Thread.Sleep(250);
}
}

Here is my aspx page:

<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:ListBox ID="ListBox1" runat="server"
Width="498px"></asp:ListBox>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ListBox1"
EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
</div>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="Button" />
</form>
"IfThenElse" <sq**********@hotmail.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl.. .
You don't have to do anything it updates by itself. hence the
updatepanel.
"MikeB" <m@nospam.comwrote in message
news:OX*************@TK2MSFTNGP06.phx.gbl...
Hello All, I am new to ajax and wanted to start by trying something
simple. I have a web form with an updatepanel and then inside the
update panel I have a listbox. Then outside of the updatepanel I have
a button. In my buttons click event in the cs / code behind, I have a
loop that just inserts items in the listbox. My question is, once I
click the button and the loop begins, how do I get it to update the
listbox? Does this make since? Basically, this kind of mimics a update
page I plan on doing next.
>
>
TIA
>




Oct 11 '07 #6
you're missing the basic concept of browsers and ajax. ajax is a pattern
used in javascript to make a web service call (via xmlhttprequest), and
then process the reponse, usually with some dynamic html.

the updatepanel when triggered:

1. javascript sends a request to page with all form fields via
xmlhttprequest
2. the server processes the form data like a normal postback
3. the server runs a special render that only renders the updatepanel(s)
4. the server sends updatepanel html back the client
5. a javascript async event is fired by xmlhttprequest when the html is
returned
6. javascript event handler replaces the contents of the updatepanel
with the html
so nothing happens in the update anel until the html is sent back.
-- bruce (sqlwork.com)
MikeB wrote:
Using AJAX, am I able to update the listbox as it is updated?

"IfThenElse" <sq**********@hotmail.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
>This will not update until the end. the browser has to get something
back.

"MikeB" <m@nospam.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>>That is what I though however, it is not updating. I must be missing
something. Here is my code behind:

protected void Button1_Click(object sender, EventArgs e)
{

Thread firstThread = new Thread(new ThreadStart(Coundown));
firstThread.Start();
}

public void Coundown()
{
for (int i = 0; i < 100; i++)
{

ListBox1.Items.Add(i.ToString());
Thread.Sleep(250);
}
}

Here is my aspx page:

<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:ListBox ID="ListBox1" runat="server"
Width="498px"></asp:ListBox>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ListBox1"
EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
</div>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="Button" />
</form>
"IfThenElse" <sq**********@hotmail.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl.. .
You don't have to do anything it updates by itself. hence the
updatepanel.
"MikeB" <m@nospam.comwrote in message
news:OX*************@TK2MSFTNGP06.phx.gbl...
Hello All, I am new to ajax and wanted to start by trying something
simple. I have a web form with an updatepanel and then inside the
update panel I have a listbox. Then outside of the updatepanel I have
a button. In my buttons click event in the cs / code behind, I have a
loop that just inserts items in the listbox. My question is, once I
click the button and the loop begins, how do I get it to update the
listbox? Does this make since? Basically, this kind of mimics a update
page I plan on doing next.
>
>
TIA
>


Oct 11 '07 #7
What about adding this to the end of your code:

UpdatePanel1.update();

This will refresh the update panel from outside of the updatepanel to
reflect the changes in the list.

Bjorn

"MikeB" <m@nospam.comwrote in message
news:eU**************@TK2MSFTNGP06.phx.gbl...
Using AJAX, am I able to update the listbox as it is updated?

"IfThenElse" <sq**********@hotmail.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
>This will not update until the end. the browser has to get something
back.

"MikeB" <m@nospam.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>>That is what I though however, it is not updating. I must be missing
something. Here is my code behind:

protected void Button1_Click(object sender, EventArgs e)
{

Thread firstThread = new Thread(new ThreadStart(Coundown));
firstThread.Start();
}

public void Coundown()
{
for (int i = 0; i < 100; i++)
{

ListBox1.Items.Add(i.ToString());
Thread.Sleep(250);
}
}

Here is my aspx page:

<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:ListBox ID="ListBox1" runat="server"
Width="498px"></asp:ListBox>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ListBox1"
EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
</div>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="Button" />
</form>
"IfThenElse" <sq**********@hotmail.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl.. .
You don't have to do anything it updates by itself. hence the
updatepanel.
"MikeB" <m@nospam.comwrote in message
news:OX*************@TK2MSFTNGP06.phx.gbl...
Hello All, I am new to ajax and wanted to start by trying something
simple. I have a web form with an updatepanel and then inside the
update panel I have a listbox. Then outside of the updatepanel I have
a button. In my buttons click event in the cs / code behind, I have a
loop that just inserts items in the listbox. My question is, once I
click the button and the loop begins, how do I get it to update the
listbox? Does this make since? Basically, this kind of mimics a update
page I plan on doing next.
>
>
TIA
>




Oct 11 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by Yarco | last post: by
4 posts views Thread by Mason Barge | last post: by
2 posts views Thread by tarun.sinha | last post: by
11 posts views Thread by walterbyrd | last post: by
10 posts views Thread by =?Utf-8?B?WWFua2VlIEltcGVyaWFsaXN0IERvZw==?= | last post: by
6 posts views Thread by Jonathan Wood | last post: by
2 posts views Thread by BobF | last post: by
11 posts views Thread by =?Utf-8?B?R2VyaGFyZA==?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.