so I got a question from some one via the cmap group, for some help with a kind of tricky asp.net ajax problem. So they had been using a pagemethod, to retrieve a list from a web service to update a datalist. Sounds simple enough... but the problem w/ using web services from client code in asp.net ajax is that the page method, which although it exists in the codebehind of a page, and used to be accessable from the instance of the page in atlas, now has to be static... anywho.... so the problem is if you call a webservice in client js, its hard to do things like bind a datalist...
so my solution/kludge was to add the postback js call of a control, to the onkeyup js event of the textbox. Basicly forcing the textbox to do a asp.net postback on a keyup (really this should be only posted back like every 3 key ups...)
heres the aspx
-
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="onkeyuppostback.aspx.cs" Inherits="onkeyuppostback" %>
-
-
<!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>Untitled Page</title>
-
</head>
-
<body>
-
<form id="form1" runat="server">
-
<div>
-
<asp:ScriptManager runat="server" ID="smTest" EnablePartialRendering="true"></asp:ScriptManager>
-
<asp:TextBox runat="server" ID="txtTest" AutoPostBack="True" OnTextChanged="txtTest_TextChanged"></asp:TextBox>
-
<asp:UpdatePanel runat="server" ID="upTest">
-
<ContentTemplate>
-
-
<asp:DataList runat="server" ID="dlTest" Width="207px">
-
<ItemTemplate>
-
<%# Container.DataItem %>
-
</ItemTemplate>
-
</asp:DataList>
-
</ContentTemplate>
-
<Triggers>
-
<asp:AsyncPostBackTrigger ControlID="txtTest" />
-
</Triggers>
-
</asp:UpdatePanel>
-
</div>
-
</form>
-
</body>
-
</html>
and here is the cs
-
using System;
-
using System.Data;
-
using System.Configuration;
-
using System.Collections;
-
using System.Web;
-
using System.Web.Security;
-
using System.Web.UI;
-
using System.Web.UI.WebControls;
-
using System.Web.UI.WebControls.WebParts;
-
using System.Web.UI.HtmlControls;
-
-
public partial class onkeyuppostback : System.Web.UI.Page
-
{
-
protected void Page_Load(object sender, EventArgs e)
-
{
-
txtTest.Attributes.Add("onkeyup", this.GetPostBackClientEvent(this.txtTest,string.Empty));
-
}
-
-
protected void txtTest_TextChanged(object sender, EventArgs e)
-
{
-
dlTest.DataSource = System.DateTime.Now.ToString();
-
dlTest.DataBind();
-
}
-
}
so yah kind of kludgy, but is an option in general for doing something in js, which will force a asp.net ajax updatepanel postback... for example, add a button somewhere, have it w/ a style display:none;, then on serverside create a js function that calls its postback function.
