Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / October 2007

Tip: Looking for answers? Try searching our database.

Basic Ajax Help

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
MikeB - 11 Oct 2007 00:33 GMT
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
IfThenElse - 11 Oct 2007 00:47 GMT
You don't have to do anything it updates by itself. hence the updatepanel.

> 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
[quoted text clipped - 5 lines]
>
> TIA
MikeB - 11 Oct 2007 01:22 GMT
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>
> You don't have to do anything it updates by itself. hence the updatepanel.
>
[quoted text clipped - 8 lines]
>>
>> TIA
IfThenElse - 11 Oct 2007 01:35 GMT
This will not update until the end.  the browser has to get something back.

> That is what I though however, it is not updating.  I must be missing
> something.  Here is my code behind:
[quoted text clipped - 48 lines]
>>>
>>> TIA
MikeB - 11 Oct 2007 01:41 GMT
Using AJAX, am I able to update the listbox as it is updated?

> This will not update until the end.  the browser has to get something
> back.
[quoted text clipped - 51 lines]
>>>>
>>>> TIA
IfThenElse - 11 Oct 2007 01:57 GMT
Your thread does not end to send anything back??

> Using AJAX, am I able to update the listbox as it is updated?
>
[quoted text clipped - 53 lines]
>>>>>
>>>>> TIA
bruce barker - 11 Oct 2007 03:30 GMT
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)

> Using AJAX, am I able to update the listbox as it is updated?
>
[quoted text clipped - 53 lines]
>>>>>
>>>>> TIA
Bjorn Sagbakken - 11 Oct 2007 20:37 GMT
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

> Using AJAX, am I able to update the listbox as it is updated?
>
[quoted text clipped - 53 lines]
>>>>>
>>>>> TIA

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.