0

它包含ajax上传器和文本框并标记上传完成时我需要做的事情我在文本框中写的内容无需刷新页面即可转到标签

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:AjaxFileUpload ID="AjaxFileUpload1" runat="server" 
        onuploadcomplete="AjaxFileUpload1_UploadComplete" />
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>

这是我的 C# 代码

protected void AjaxFileUpload1_UploadComplete(object sender,AjaxControlToolkit.AjaxFileUploadEventArgs e)
{
    string path = Server.MapPath("~/nn/") + e.FileName;
    AjaxFileUpload1.SaveAs(path);
    Label1.Text = TextBox1.Text;
}

问题是 ajax 控制器事件感觉不到 .net 组件有什么帮助吗?

4

1 回答 1

0

我相信您需要将代码包装在更新面板控件中。

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <asp:AjaxFileUpload ID="AjaxFileUpload1" runat="server" 
                    onuploadcomplete="AjaxFileUpload1_UploadComplete" />
                <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>
</form>
</body>
</html>
于 2012-12-12T14:06:51.367 回答