刚开始使用AJAX,并在Microsoft®70515书中尝试了一个简单示例。然而,代码似乎没有工作,我不明白为什么不 - 因为它似乎确定。无法让AJAX代码起作用
- 编辑:由于某种原因,该代码的一部分没有得到公布,(即使我写这现在的代码看起来怪异,这就像我不能发布我的代码?)我”现在已经有fixad了 - 但是投票结果如何呢?我真的不知道我的问题是什么愚蠢的。请解释。
希望有人能发现的问题,并帮助我在这里:)
标记的.aspx:
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="AjasxTest._Default" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager>
<br /><br />
<script type="text/javascript">
function ClientCallbackFunction(args) {
window.LabelMessage.innerText = args;
}
</script>
</asp:Content>
<asp:Content ID="Content1" runat="server" ContentPlaceHolderID="FooterContent">
<asp:DropDownList ID="DropDownListChoice" runat="server" OnChange="MyServerCall(DropDownListChoice.value)">
<asp:ListItem>Choice 1</asp:ListItem>
<asp:ListItem>Choice 2</asp:ListItem>
<asp:ListItem>Choice 3</asp:ListItem>
</asp:DropDownList>
<asp:Label ID="LabelMessage" runat="server"></asp:Label>
</asp:Content>
代码隐藏:
namespace AjasxTest
{
public partial class _Default : System.Web.UI.Page, System.Web.UI.ICallbackEventHandler
{
protected void Page_Load(object sender, EventArgs e)
{
string callbackRef = Page.ClientScript.GetCallbackEventReference(this, "args", "ClientCallbackFunction", "");
string callbackScript = String.Format("function MyServerCall(args) {{{0};}}", callbackRef);
Page.ClientScript.RegisterClientScriptBlock(this.GetType(),"MyServerCall", callbackScript, true);
}
public string GetCallbackResult()
{
return _callbackArgs;
}
string _callbackArgs;
public void RaiseCallbackEvent(string eventArgument)
{
_callbackArgs = eventArgument;
}
}
}
嗨,你可以发布ajax请求创建功能。在解释你的问题时要更加清楚,不要直言不讳地说。只要说明你的期望是什么以及它的行为如何? – AmGates 2012-02-07 09:08:59
对不起,我不知道我在做什么错,但我的代码不会发布:(我已经尝试了四次,但每次都会搞砸。以前从未遇到过这个问题。 – 2012-02-07 11:33:43