剛開始使用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