我的 asp 项目上有一个图像按钮,可以浏览图像并显示。我正在为我的项目使用脚本。
这是我的代码:
ASPX:
<asp:Panel ID="stage" runat="server" cssClass="containment-wrapper" style="border:1px solid #000000;">
<asp:ImageButton ID="imgBrowse" runat="server" Height="375px" Width="640px" src="#" />
<input type='file' id="inpUploader" style="visibility: hidden;"/>
</asp:Panel>
JS source :
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#imgBrowse').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
$("#inpUploader").change(function () {
readURL(this);
});
CS:
protected void Page_Load(object sender, EventArgs e)
{
imgBrowse.Attributes.Add("onclick", "document.getElementById('inpUploader').click();");
}
我的代码正在运行,并且在我选择图像后显示图像,但几秒钟后图像因页面重新加载而丢失。
最佳答案
我解决了我的问题。
只需添加return false;
。
protected void Page_Load(object sender, EventArgs e)
{
imgBrowse.Attributes.Add("onclick", "document.getElementById('inpUploader').click(); return false;");
}
关于c# - 禁用图像按钮上的回发单击 asp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21655312/