Wednesday, March 21, 2012

AJAX and formview

I downloaded the tool kit, but I am not sure which "example" I want to use. On my development web site:http://ptkvb.delfraisse.com, I have a formview to display "programs". Right now it has 1, 2 and 3 for the different programs. The problem is the post back. Would AJAX be a solution for me? Should I use formviews at all? I would like to auto switch to each of them every 30 seconds as well. I also would like to change the buttons on the bottom to "Prev * *(*) * * Next" type style (as displayed on this idea graphic:http://delfraisse.com/external/ptk/ptk-default.gif).

Thanks for your time.

Hi,

I made a sample according to your requirement with pure javascript, please try it:

<%@. Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> protected void Page_Load(object sender, EventArgs e) { } </script><html xmlns="http://www.w3.org/1999/xhtml" ><head id="Head1" runat="server"> <title>Untitled Page</title><script language="javascript" type="text/javascript">// <!CDATA[var index = 0;var projects = new Array();function pageLoad() { projects[0]=$get("Panel1"); projects[1]=$get("Panel2"); projects[2]=$get("Panel3"); displayProject(); window.setInterval(autoIncrease, 1000);}function Button1_onclick() { --index; displayProject();}function Button2_onclick() { ++index; displayProject();}function autoIncrease() { ++index; displayProject();}function displayProject() { for(var i=0; i projects[i].style.display ="none"; index = index%3; projects[index].style.display = "";}// ]]></script></head><body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:Panel ID="Panel1" runat="server" Height="50px" Width="125px"> Project 1</asp:Panel> <asp:Panel ID="Panel2" runat="server" Height="50px" Width="125px"> Project 2</asp:Panel> <asp:Panel ID="Panel3" runat="server" Height="50px" Width="125px"> Project 3</asp:Panel> <input id="Button1" type="button" value="Previous" onclick="return Button1_onclick()" /> <input id="Button2" type="button" value="Next" onclick="return Button2_onclick()" /> </form></body></html>

That only shows three projects. I need it to pull from the database and pull as many projects are in there. Right now my post back script is pulling from the database, that way I can add a project with a form or directly in the database.


The sample is mainly used to demonstrate how to use javascript to achieve your requirements, you may create panels and javascript dynamically according to the number of records in database.

No comments:

Post a Comment