Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net event.preventDefault()阻止所有onclick事件,而不仅仅是一个_Asp.net_Jquery_Preventdefault - Fatal编程技术网

Asp.net event.preventDefault()阻止所有onclick事件,而不仅仅是一个

Asp.net event.preventDefault()阻止所有onclick事件,而不仅仅是一个,asp.net,jquery,preventdefault,Asp.net,Jquery,Preventdefault,我想给我的ASP.NET文件上传控件打上烙印,因为这无法在OOB中实现,所以我选择用javascript复制它的功能 我将“浏览”按钮onclickevent附加到我的按钮上,并使用event.preventDefault()按预期工作。但我还有另外两个按钮;保存、删除,这是asp.net的常规按钮。在我的“自定义”浏览按钮上触发onclick事件后,其他两个按钮onclick事件将不会触发 [Javascript] $(document).ready(function () { //

我想给我的ASP.NET文件上传控件打上烙印,因为这无法在OOB中实现,所以我选择用javascript复制它的功能

我将“浏览”按钮
onclick
event附加到我的按钮上,并使用
event.preventDefault()
按预期工作。但我还有另外两个按钮;保存、删除,这是asp.net的常规按钮。在我的“自定义”浏览按钮上触发
onclick
事件后,其他两个按钮
onclick
事件将不会触发

[Javascript]

$(document).ready(function () {
    // The "custom" browse button.
    $('#<%=ProfilePictureBrowsePicture.ClientID%>').click(function (event) {
        event.preventDefault();
        $('#<%=ProfilePictureUpload.ClientID%>').click();
    });

    // the "custom" fileupload box to display the selected image path.
    $('#<%=ProfilePictureUpload.ClientID%>').change(function () {
        $('#<%=ProfilePictureShowFile.ClientID%>').val($(this).val());
    });
});
$(文档).ready(函数(){
//“自定义”浏览按钮。
$('#')。单击(函数(事件){
event.preventDefault();
$('#')。单击();
});
//“自定义”文件上载框以显示选定的图像路径。
$('#')。更改(函数(){
$('#').val($(this.val());
});
});
[HTML]

<asp:FileUpload ID="ProfilePictureUpload" CssClass="filename" runat="server" />
<asp:TextBox ID="ProfilePictureShowFile" CssClass="fba-txtBox showSelectedFile" runat="server" /><br />
<asp:Button ID="ProfilePictureBrowsePicture" CssClass="btnYellow" runat="server"  Text="Gennemse" ToolTip="Gennemse billede" />
<asp:Button ID="ProfilePictureUploadButton" CssClass="btnYellow" runat="server" Text="Gem" ToolTip="Gem billede" OnClick="ProfilePictureUploadButton_Click" />
<asp:Button ID="ProfilePictureDeleteButton" CssClass="btnYellow" runat="server" Text="Slet" ToolTip="Slet billede" OnClick="ProfilePictureDeleteButton_Click" EnableViewState="false" />


我尝试用谷歌搜索if
event.preventDefault()
影响onclick事件,而不是它在函数中出现的事件,但没有成功

谁能启发我

event.preventDefault();   // Cancels the postback  ...
$('#<%=ProfilePictureUpload.ClientID%>').click(); 
因此,这里的客户端.click()事件与Onclick server事件不同

因为您正在使用preventDefault停止回发,服务器端事件显然不会触发


要触发服务器端事件,您可以使用
\u doPostback()
或删除
preventDefault()
方法。

我用
关闭了asp.net按钮并删除了
事件。preventDefault()
,但问题仍然存在。这很奇怪。问题是您正在单击ProfilePictureUpload按钮,并希望触发ProfilePictureUpload按钮\单击事件…它们是两个不同的控件
ProfilePictureUpload
是一个文件上载控件,
ProfilePictureUploadButton
是一个按钮控件。我只希望每当我单击
ProfilePictureUploadButton
,而不是
ProfilePictureUploadButton
,单击时触发
ProfilePictureUploadButton
OnClick="ProfilePictureUploadButton_Click"  // This is server side event