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 に答える