【发布时间】:2012-02-07 08:59:38
【问题描述】:
刚开始使用 AJAX 并尝试了 microsoft 70515 书中的一个简单示例。但是,代码似乎不起作用,我不知道为什么不能 - 因为它似乎没问题。
- 编辑:由于某种原因,部分代码没有发布,(即使我现在正在写这个代码看起来很奇怪,好像我不能发布我的所有代码??)我已经修复了现在-但是反对票是怎么回事?我真的看不出我的问题有什么愚蠢的。请解释一下。
希望有人能发现问题并在这里帮助我:)
标记.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请求创建功能吗?并且更清楚地解释你的问题,不要直言不讳地说不工作。只需说明您的期望是什么以及它的表现如何?
-
对不起,我不知道我做错了什么,但我的代码不会发布:(我已经尝试了四次,但每次都搞砸了。以前从未遇到过这个问题。跨度>
标签: c# javascript asp.net ajax