using Ajax with a Datalist and FormView

Last post 11-06-2009 3:51 PM by atifsarfraz. 1 replies.

Sort Posts:

  • using Ajax with a Datalist and FormView

    11-06-2009, 10:19 AM
    • Member
      4 point Member
    • aadeveloper
    • Member since 06-04-2009, 7:22 PM
    • Posts 20

     Hi everyone,

    I am trying to use a data list to show a bunch of images.  When the user clicks on an image, it does a postback and populates the formview with the image selected.  It's annoying to look at when the page refreshes each time.

    Is there a way that I can use AJAX to refresh the formview without doing a postback.

    Thanks.

  • Re: using Ajax with a Datalist and FormView

    11-06-2009, 3:51 PM
    Answer
    • Participant
      1,738 point Participant
    • atifsarfraz
    • Member since 10-06-2009, 3:55 PM
    • Florida
    • Posts 275

    1- You can definitely use AJAX and it is quite easy to use. Here is a sample showing DataList as a trigger for the updatepanel.

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Practice.WebForm1" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Image Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:DataList ID="DataList1" runat="server">
        </asp:DataList>    
        <div>
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <asp:Panel ID="PanelToShowImage" runat="server">
                </asp:Panel>      
            </ContentTemplate>
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="DataList1" 
                        EventName="SelectedIndexChanged" />
                </Triggers>
            </asp:UpdatePanel>
        </div>
        </form>
    </body>
    </html>
    

    2- You can also do this through a javascript instead of a full postback. So if your datalist already has the imageurl you can have a javascript eventhandler set the image path inside the Div.


    Regards,

    Atif Sarfraz

    Please mark this post as answered if it helped you!
Page 1 of 1 (2 items)