Showing posts with label example. Show all posts
Showing posts with label example. Show all posts

Wednesday, March 28, 2012

AJAX Beginner HELP!!

I checked out the instructional videos provided on this site for the Microsoft AJAX but it is all for the ATLAS release.

Take for example here is some of the code that I have from one of the videos

<%

@dotnet.itags.org.PageLanguage="VB"AutoEventWireup="false"CodeFile="Default.aspx.vb"Inherits="_Default" %>

<%

@dotnet.itags.org.RegisterAssembly="Microsoft.Web.Atlas"Namespace="Microsoft.Web.UI"TagPrefix="atlas" %>

<%

@dotnet.itags.org.RegisterAssembly="AtlasControlToolkit"Namespace="AtlasControlToolkit"TagPrefix="atlastoolkit" %>

<!

DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<

htmlxmlns="http://www.w3.org/1999/xhtml">

<

headrunat="server">

<

atlas:ScriptManagerID="PageScriptManager"runat="server"EnablePartialRendering="True"/>

<

atlastoolkit:HoverMenuExtenderID="HoverMenuExtender1"runat="server"><atlastoolkit:HoverMenuPropertiesTargetControlID="btnProduct"PopupControlID="PanelPopUp"PopupPosition="Left"PopDelay="25"/></atlastoolkit:HoverMenuExtender>

<

title>Untitled Page</title>

<

styletype="text/css">

/*Hover Menu*/

.popupMenu

{position:absolute;visibility:hidden;background-image:url(images/header.png);opacity:.9;filter:alpha(opacity=90);

}

.popupHover

{background-image:url(images/header-opened.png);background-repeat:repeat-x;background-position:lefttop;background-color:#F5F7F8;

}

</

style>

</

head>

<

bodystyle="text-align: left"><formid="form1"runat="server"><br/><table><tr><tdstyle="width: 80px"><asp:PanelID="PanelPopUp"runat="server"Width="80"BackColor="white"CssClass="popupMenu"><asp:LinkButtonID="BtnUpdate"runat="server"CausesValidation="True"CommandName="Update"Text="Update"></asp:LinkButton> <br/><asp:LinkButtonID="BtnDelete"runat="server"CausesValidation="False"CommandName="Cancel"Text="Delete"></asp:LinkButton> </asp:Panel></td><tdstyle="width: 100px"><asp:LinkButtonID="btnProduct"runat="server"Width="273px">Product Number One</asp:LinkButton></td></tr></table></form>

</

body>

</

html>

Now the big issue is I just installed the new Beta 2 I do not have the ATLAS installed. I do not get any options for AJAX controls or code and I created a new website using the option for "ASP.NET AJAX-Enabled Web Site"

Please tell me what is going wrong do I need to uninstall and reinstall everything.

Also I am using the Visual Studio Express Web

Thank you for any help you can provide on this

hello.

1st, the ajax extensions have changed the prefix name used...there's a breaking change document which explains this on the ajax.asp.net site

you should also note that you need to download the toolkit pack from codeplex in order to use it...

Monday, March 26, 2012

Ajax autocomplete method

Hi! Is there an example of doing the ajax autocomplete using sql as the back end. This is the method they have on there:publicstring[] GetCompletionList(string prefixText,int count)

{

if (count == 0)

{

count = 10;

}

Random random =newRandom();

List<string> items =newList<string>(count);

for (int i = 0; i < count; i++)

{

char c1 = (char)random.Next(65, 90);

char c2 = (char)random.Next(97, 122);

char c3 = (char)random.Next(97, 122);

items.Add(prefixText + c1 + c2 + c3);

}

return items.ToArray();

}

Basically I'd like to change this method to be an sql server method. Thanks for any tips

This is a stripped down example that might help get you started:

 [WebMethod]
public string[] GetCustomerList(string prefixText,int count)
{
OleDbConnection conn =new OleDbConnection("ConnectionStringGoesHere");
OleDbCommand cmd =new OleDbCommand();

cmd.Connection = conn;

cmd.CommandText =string.Format("select customer_name from customers where customer_name like '%{0}%'", prefixText);

conn.Open();

OleDbDataReader dr = cmd.ExecuteReader();

List<string> result =new List<string>();

while (dr.Read())
result.Add(dr[0].ToString());

conn.Close();

return result.ToArray();
}

Please note, it isn't really representative of following database best practices. It should point you in the right direction though.

Thank you! Works good!


Just make sure you tidy up the database access if you're going to use this in production. That code is vulnerable to SQL injection, which is fairly bad when it's hooked up to a web service.

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.