在网页上点击按钮事件时如何显示图像?

huangapple go评论65阅读模式
英文:

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 />

huangapple
  • 本文由 发表于 2023年6月19日 16:48:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/76505046.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定