如何清除 asyncfileupload 的文本框值..?

发布于 2024-08-12 23:39:44 字数 243 浏览 8 评论 0原文

有一个按钮(MyButton)。 单击此按钮时,会出现一个 modalpopup(MyPopup),其中包含一个 asyncfileupload ajax 控件、“确定”按钮和“取消”按钮。

asyncfileupload 功能的浏览功能工作正常,没问题。 但是回发后,如果我再次单击 MyButton,弹出窗口将显示在 asyncfileupload 控件的文本框中,其中包含先前的路径。

怎么清除呢...!

提前致谢。

There is one button(MyButton).
OnClick of this button a modalpopup(MyPopup) appears with one asyncfileupload ajax control, Ok button and Cancel button.

The browse functionality of the asyncfileupload functionality is working fine, No problem.
But after postback, if I click the MyButton again, the popup appearing with the previous path in the asyncfileupload control's textbox.

How to clear it ... !

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

荒岛晴空 2024-08-19 23:39:44

所提出的方法都不适合我。
问题并不特定于 AsyncFileUpload,而是特定于 input[type=file]。

最后,我找到了一种适用于 javascript 的方法:

function uploadComplete(sender, args) {
    jQuery(sender.get_element()).find("input[type='file']")[0].form.reset();
}

None of the proposed ways worked for me.
The problem is not specific to AsyncFileUpload, but to the input[type=file].

Finally, I found a way that worked for me with javascript:

function uploadComplete(sender, args) {
    jQuery(sender.get_element()).find("input[type='file']")[0].form.reset();
}
眸中客 2024-08-19 23:39:44

将 AsyncFileUpload 描述符的属性设置为 OnClientUploadComplete="UploadComplete" 并使用下一个 JS:

function UploadComplete(sender, arg2) {
  // clear file
  var fileInputElement = sender.get_inputFile();
  fileInputElement.value = "";
}

您也可以将任何操作/样式应用于“fileInputElement”。

Set up attribute of AsyncFileUpload descriptor to OnClientUploadComplete="UploadComplete" and use next JS:

function UploadComplete(sender, arg2) {
  // clear file
  var fileInputElement = sender.get_inputFile();
  fileInputElement.value = "";
}

You can apply any actions/styles to the "fileInputElement" too.

只为一人 2024-08-19 23:39:44

如果您尝试在客户端清除它,这对我有用。

<script type = "text/javascript">
function clearContents() {
    var AsyncFileUpload = $get("<%=AsyncFileUpload1.ClientID%>");
    var txts = AsyncFileUpload.getElementsByTagName("input");
    for (var i = 0; i < txts.length; i++) {
        if (txts[i].type == "file") {
            txts[i].value = "";
            txts[i].style.backgroundColor = "transparent";
        }
    }
}

function uploadComplete(sender) {
    clearContents();
}
</script>

this worked for me if you're attempting to clear it client side.

<script type = "text/javascript">
function clearContents() {
    var AsyncFileUpload = $get("<%=AsyncFileUpload1.ClientID%>");
    var txts = AsyncFileUpload.getElementsByTagName("input");
    for (var i = 0; i < txts.length; i++) {
        if (txts[i].type == "file") {
            txts[i].value = "";
            txts[i].style.backgroundColor = "transparent";
        }
    }
}

function uploadComplete(sender) {
    clearContents();
}
</script>
逐鹿 2024-08-19 23:39:44

扩展 ador 上面的答案:

function uploadComplete(sender, args) {
    var uploadField = $(sender.get_element()).find("input[type='file']");
    uploadField[0].form.reset();
    uploadField.each(function () { $(this).css("background-color", "white"); });
}

To expand ador's answer above:

function uploadComplete(sender, args) {
    var uploadField = $(sender.get_element()).find("input[type='file']");
    uploadField[0].form.reset();
    uploadField.each(function () { $(this).css("background-color", "white"); });
}
花开雨落又逢春i 2024-08-19 23:39:44

假设您使用 Ajax Control Toolkit 中的控件,您可以连接到 OnClientUploadedComplete 句柄,上传完成后客户端会调用该句柄。您想在模式弹出窗口上调用 hide

 var modalPopupBehavior = $find('popupID');
 modalPopupBehavior.hide();

Assuming you're using the control from Ajax Control Toolkit you can hook into the OnClientUploadedComplete handle which is called on the client side once the upload is complete. You want to call hide on the modal popup

 var modalPopupBehavior = $find('popupID');
 modalPopupBehavior.hide();
独守阴晴ぅ圆缺 2024-08-19 23:39:44

这是对 Jmoon 答案的更正。如果您想在上传完成后而不是在其他用户操作后清除 AsyncFileUpload 文本,这非常有用。

function clearContents() {
    var AsyncFileUpload = $("#<%=AsyncFileUpload1.ClientID%>")[0];
    var txts = AsyncFileUpload.getElementsByTagName("input");
    for (var i = 0; i < txts.length; i++) {
        txts[i].value = "";
        txts[i].style.backgroundColor = "transparent";
    }
}

This is a correction for the Jmoon's answer. This is usefull if you want to clear AsyncFileUpload text not after upload complete but after some other user action.

function clearContents() {
    var AsyncFileUpload = $("#<%=AsyncFileUpload1.ClientID%>")[0];
    var txts = AsyncFileUpload.getElementsByTagName("input");
    for (var i = 0; i < txts.length; i++) {
        txts[i].value = "";
        txts[i].style.backgroundColor = "transparent";
    }
}
眼趣 2024-08-19 23:39:44

这肯定会清除文本框:

var AsyncFileUpload = $get("<%=AsyncFileUpload1.ClientID%>");
    var txts = AsyncFileUpload.getElementsByTagName("input");
    for (var i = 0; i < txts.length; i++) {
        if (txts[i].type == "file") {
            txts[i].style.backgroundColor = "transparent";
            txts[i].form.reset();
        }
    }

This will definitely clear the textbox:

var AsyncFileUpload = $get("<%=AsyncFileUpload1.ClientID%>");
    var txts = AsyncFileUpload.getElementsByTagName("input");
    for (var i = 0; i < txts.length; i++) {
        if (txts[i].type == "file") {
            txts[i].style.backgroundColor = "transparent";
            txts[i].form.reset();
        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文