英文:
how to show image on button click event on web page?
问题
我正在工作在asp.net上,在这里我想在按钮单击事件上显示图片,图片应该出现在第3行,但图片出现在第10行完成后(即Button1_Click()事件完成后)。
如何使图片在第3行执行时出现在网页上,而不是在第10行完成后出现(即Button1_Click()事件完成后)的解决方案是什么?
英文:
I'm working on asp.net, here I want to show IMAGE on button click event, Image should appear at line no.3, but image is appearing after completion of line no 10(i.e. after completion of Button1_Click() event)
what will be the solution to make image appear on execution of line 3?
#default.aspx
1. <asp:FileUpload CssClass="SelectFile" ID="FileUpload1" runat="server" />
2. <br />
3. <asp:Button CssClass="gen" ID="Button1" runat="server" OnClick="Button1_Click" Text="Generate" />
4. <br />
#default.aspx.cs
1.protected void Button1_Click(object sender, EventArgs e)
2.{
3. Image.Visible = true;
4. if (FileUpload1.HasFile)
5. {
6. ////////
7. code
8. ////////
9. }
10.}
what will be solution to make Image appear at line no.3 on web page, rather than appearing after completion of line no 10(i.e. after completion of Button1_Click() event)
答案1
得分: 1
你需要在客户端而不是服务器上执行这个操作。
这段JavaScript通过id选择要显示的图像,id为'myImage' - 你需要将其更改为图像的Id。
<html>
<head>
<script type="text/javascript">
function myClosure(){
var myImage = document.getElementById('myImage');
myImage.style.display = 'block';
}
</script>
</head>
在页面上这样调用它:
<asp:FileUpload CssClass="SelectFile" ID="FileUpload1" runat="server" />
2. <br />
3. <asp:Button CssClass="gen" ID="Button1" runat="server" OnClick="Button1_Click" OnClientClick="myClosure()" Text="Generate" />
4. <br />
英文:
You need to do that on the client, not the server.
This JavaScript selects the image that you want to display by the id of 'myImage' - you would need to change that to the image's Id.
<html>
<head>
<script type="text/javascript">
function myClosure(){
var myImage = document.getElementById('myImage');
myImage.style.display = 'block';
}
</script>
</head>
<body>
Call it like this:
<asp:FileUpload CssClass="SelectFile" ID="FileUpload1" runat="server" />
2. <br />
3. <asp:Button CssClass="gen" ID="Button1" runat="server" OnClick="Button1_Click" OnClientClick="myClosure()" Text="Generate" />
4. <br />
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论