PC Review


Reply
Thread Tools Rate Thread

Basic Ajax Help

 
 
MikeB
Guest
Posts: n/a
 
      11th Oct 2007
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


 
Reply With Quote
 
 
 
 
IfThenElse
Guest
Posts: n/a
 
      11th Oct 2007
You don't have to do anything it updates by itself. hence the updatepanel.


"MikeB" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
MikeB
Guest
Posts: n/a
 
      11th Oct 2007
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" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> You don't have to do anything it updates by itself. hence the updatepanel.
>
>
> "MikeB" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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
>>

>
>



 
Reply With Quote
 
IfThenElse
Guest
Posts: n/a
 
      11th Oct 2007
This will not update until the end. the browser has to get something back.

"MikeB" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
>> You don't have to do anything it updates by itself. hence the
>> updatepanel.
>>
>>
>> "MikeB" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>> 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
>>>

>>
>>

>
>



 
Reply With Quote
 
MikeB
Guest
Posts: n/a
 
      11th Oct 2007
Using AJAX, am I able to update the listbox as it is updated?

"IfThenElse" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> This will not update until the end. the browser has to get something
> back.
>
> "MikeB" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
>> 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" <(E-Mail Removed)> wrote in message
>> news:%(E-Mail Removed)...
>>> You don't have to do anything it updates by itself. hence the
>>> updatepanel.
>>>
>>>
>>> "MikeB" <(E-Mail Removed)> wrote in message
>>> news:(E-Mail Removed)...
>>>> 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
>>>>
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
IfThenElse
Guest
Posts: n/a
 
      11th Oct 2007
Your thread does not end to send anything back??


"MikeB" <(E-Mail Removed)> wrote in message
news:eUtDJ$(E-Mail Removed)...
> Using AJAX, am I able to update the listbox as it is updated?
>
> "IfThenElse" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
>> This will not update until the end. the browser has to get something
>> back.
>>
>> "MikeB" <(E-Mail Removed)> wrote in message
>> news:%(E-Mail Removed)...
>>> 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" <(E-Mail Removed)> wrote in message
>>> news:%(E-Mail Removed)...
>>>> You don't have to do anything it updates by itself. hence the
>>>> updatepanel.
>>>>
>>>>
>>>> "MikeB" <(E-Mail Removed)> wrote in message
>>>> news:(E-Mail Removed)...
>>>>> 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
>>>>>
>>>>
>>>>
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
bruce barker
Guest
Posts: n/a
 
      11th Oct 2007
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" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
>> This will not update until the end. the browser has to get something
>> back.
>>
>> "MikeB" <(E-Mail Removed)> wrote in message
>> news:%(E-Mail Removed)...
>>> 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" <(E-Mail Removed)> wrote in message
>>> news:%(E-Mail Removed)...
>>>> You don't have to do anything it updates by itself. hence the
>>>> updatepanel.
>>>>
>>>>
>>>> "MikeB" <(E-Mail Removed)> wrote in message
>>>> news:(E-Mail Removed)...
>>>>> 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
>>>>>
>>>>
>>>

>>

>
>

 
Reply With Quote
 
Bjorn Sagbakken
Guest
Posts: n/a
 
      11th Oct 2007
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" <(E-Mail Removed)> wrote in message
news:eUtDJ$(E-Mail Removed)...
> Using AJAX, am I able to update the listbox as it is updated?
>
> "IfThenElse" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
>> This will not update until the end. the browser has to get something
>> back.
>>
>> "MikeB" <(E-Mail Removed)> wrote in message
>> news:%(E-Mail Removed)...
>>> 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" <(E-Mail Removed)> wrote in message
>>> news:%(E-Mail Removed)...
>>>> You don't have to do anything it updates by itself. hence the
>>>> updatepanel.
>>>>
>>>>
>>>> "MikeB" <(E-Mail Removed)> wrote in message
>>>> news:(E-Mail Removed)...
>>>>> 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
>>>>>
>>>>
>>>>
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Basic AJAX Question Jonathan Wood Microsoft ASP .NET 7 1st Feb 2008 04:56 PM
Basic AJAX Toolkit question JJ Microsoft ASP .NET 0 21st Nov 2007 11:27 AM
Basic AJAX question. JDeats Microsoft ASP .NET 4 11th Sep 2007 07:27 AM
web basic questions ajax TARUN Microsoft Access Getting Started 3 6th May 2006 10:56 PM
ajax basic tarun.sinha@gmail.com Microsoft ASP .NET 2 17th Apr 2006 04:14 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:12 AM.