使用ASP.net组件实现Ajax组件

时间:2012-12-12 13:03:05

标签: asp.net html ajax

它包含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组件 有什么帮助吗?

1 个答案:

答案 0 :(得分: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>