页面上有一文本框,当我输图片名,点击确定按钮,图片就会显示相应的图片(也就是图片控件怎样根据图片名不一样,显示不同的图片)。这样的代码怎么写????

解决方案 »

  1.   

    <img id=img1 src="图片地址" onclick="javascript:img1toimg2();"><script>
    function img1toimg2(){
    img1.src="img2.jpg"
    }
    </script>
      

  2.   

    错了错了,忘记这里是asp.net的了
      

  3.   

    testCilentEvent.aspx.
    -------------
    <form id="Form1" method="post" runat="server">
    <asp:Image id="Image1" runat="server" ImageUrl="../admin/images/admin_top_open.gif"></asp:Image>
    <asp:TextBox id="TextBox2" runat="server"></asp:TextBox>
    <asp:Button id="Button2" runat="server" Text="Button"></asp:Button></P>
    </FONT>
    </form>
    --------------------------------------
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;namespace aspnetc.test
    {
    /// <summary>
    /// testCilentEvent 的摘要说明。
    /// </summary>
    public class testCilentEvent : System.Web.UI.Page
    {
    protected System.Web.UI.WebControls.TextBox TextBox1;
    protected System.Web.UI.WebControls.Button Button1;
    protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator1;
    protected System.Web.UI.WebControls.Image Image1;
    protected System.Web.UI.WebControls.Button Button2;
    protected System.Web.UI.WebControls.TextBox TextBox2;
    protected System.Web.UI.WebControls.Button btnTest;

    private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面 } #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {     this.Button2.Click += new System.EventHandler(this.Button2_Click);
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion private void Button2_Click(object sender, System.EventArgs e)
    {
    Image1.ImageUrl ="../admin/images/"+TextBox2.Text;
    }
    }
    }
      

  4.   

    <img id=img1 src="图片地址" onclick="javascript:img1toimg2();">
    <script>
    function img1toimg2(){
    img1.src="img2.jpg"
    }
    </script>上面的不对吧!我有很多张图片,且图片名是在文本框中输入的
      

  5.   

    哈哈,猪头来了!猪头的思路正确,哈哈!Image1.ImageUrl ="../admin/images/"+TextBox2.Text;
    ="../admin/images/"+TextBox2.Text;还要加扩展名吧,比如Image1.ImageUrl="="../admin/images/""+TextBox2.Text+".jpg"
      

  6.   

    哈哈,猪头来了!猪头的思路正确,哈哈!
    toin((材娃)) 
    ----------------------
    别这样说我,多不好意思,我就会这样的问题,难的就不行了~~~~楼主既然是ASP.NET那么用<asp:Image id="Image1" runat="server" ImageUrl="../admin/images/admin_top_open.gif"></asp:Image>服务器控件实现起来很方便的.
    代码量很少的,建议楼主使用.html控件img是用于静态的地方是好一些的.
      

  7.   

    我用的是html控件img,代码怎么在后台完成????
    大家帮忙想一想!!!
      

  8.   

    我用的是html控件img,代码怎么在后台完成????
    大家帮忙想一想!!!
      

  9.   

    我用的是html控件img,代码怎么在后台完成????
    大家帮忙想一想!!!
      

  10.   

    我用的是html控件img,代码怎么在后台完成????
    大家帮忙想一想!!!
      

  11.   

    我用的是html控件img,代码怎么在后台完成????
    大家帮忙想一想!!!
      

  12.   

    我用的是html控件img,代码怎么在后台完成????
    大家帮忙想一想!!!
    ------------------------
    楼主,把HTML的IMG删除了,加上
    asp:Image id="Image1" runat="server" ImageUrl="../admin/images/admin_top_open.gif"></asp:Image>
    不可以吗?
    极度郁闷.......
      

  13.   

    我的img是在后台动态加上去的
    大家帮忙想一想!!!
      

  14.   

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <TITLE> New Document </TITLE>
    <META NAME="Generator" CONTENT="EditPlus">
    <META NAME="Author" CONTENT="">
    <META NAME="Keywords" CONTENT="">
    <META NAME="Description" CONTENT="">
    </HEAD><BODY><input type ="text" id ="txtPic" ><input type ="button" onclick ="showImage();" value ="查看">
    <img id=img1 src="图片地址" onclick="javascript:img1toimg2();"><script>
    function showImage(){
    img1.src="C:\\Documents and Settings\\Administrator\\桌面\\"+txtPic.value;
    }
    </script></BODY>
    </HTML>
    ------------------
    楼主测试同过。
    C:\\Documents and Settings\\Administrator\\桌面\\---是文件目录,根据需要请指定.
      

  15.   

    什么呀!!我一定要用html的控件image
    你用的是Web控件了
      

  16.   

    楼主,那里有WEB控件了?请指出来~~~~
    --------------------------------------------------
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <TITLE> New Document </TITLE>
    <META NAME="Generator" CONTENT="EditPlus">
    <META NAME="Author" CONTENT="">
    <META NAME="Keywords" CONTENT="">
    <META NAME="Description" CONTENT="">
    </HEAD><BODY><input type ="text" id ="txtPic" ><input type ="button" onclick ="showImage();" value ="查看">
    <img id=img1 src="图片地址" onclick="javascript:img1toimg2();"><script>
    function showImage(){
    img1.src="C:\\Documents and Settings\\Administrator\\桌面\\"+txtPic.value;
    }
    </script></BODY>
    </HTML>
    ------------------
    楼主测试同过。
    C:\\Documents and Settings\\Administrator\\桌面\\---是文件目录,根据需要请指定.
      

  17.   

    我要在后台的.cs中完成,我的img是后台动态生成的
      

  18.   

    我要在后台的.cs中完成,我的img是后台动态生成的----------------------------------------
    我要在后台的.cs中完成.完成什么?我的img是后台动态生成的,如何动态生成?楼主,我太笨了,不理解什么意思,能否赐教?
      

  19.   

    我要在后台的.cs中完成.完成什么?在后台完成输入不同图片名出来不同图片的操作。我的img是后台动态生成的,如何动态生成?tc2.Text = "<IMG  id=img1 height='127' width='100'>"
      

  20.   

    我要在后台的.cs中完成.完成什么?在后台完成输入不同图片名出来不同图片的操作。我的img是后台动态生成的,如何动态生成?tc2.Text = "<IMG  id=img1 height='127' width='100'>"
      

  21.   

    1.我要在后台的.cs中完成.完成什么?
    在后台完成输入不同图片名出来不同图片的操作。
    -------------------------------------------
    id=img1 会变化吗?若不会,建议楼主在aspx中实现改功能;在aspx.cs中也可以完成该功能,那就是把
    <script>
    function showImage(){
    img1.src="C:\\Documents and Settings\\Administrator\\桌面\\"+txtPic.value;
    }
    </script>
    输出到客户端.在确认按钮中加入一个属性onclick = showImage(),以调用showImage();
    -------------------------------------------------------------------
    2.
    我的img是后台动态生成的,如何动态生成?tc2.Text = "<IMG  id=img1 height='127' width='100'>"我不明白楼主为什么不问题搞的这么复杂!要把图片的显示放在tc2.Text里.直接使用<asp:Image...>多方便!!
      

  22.   

    或直接把<IMG  id=img1 height='127' width='100'>放在aspx中.
      

  23.   

    我不明白楼主为什么不问题搞的这么复杂!要把图片的显示放在tc2.Text里.直接使用<asp:Image...>多方便!!当然有用处的哪!!我在Table中生成Image
      

  24.   

    id=img1 会变化吗?若不会,建议楼主在aspx中实现改功能;在aspx.cs中也可以完成该功能,那就是把
    <script>
    function showImage(){
    img1.src="C:\\Documents and Settings\\Administrator\\桌面\\"+txtPic.value;
    }
    </script>
    输出到客户端.在确认按钮中加入一个属性onclick = showImage(),以调用showImage();
    _________________________________________________________________________________
    我说了很多遍了,要在后台中完成,不要在前台定义函数。
      

  25.   

    那你为什么不每次更换图片时都去生成一次图片呢?你想先生成图片(html控件动态生成),
    又要在服务器的后续事件(服务端)中捕获先前生成的html图片控件?如果是,这本身就不是个好的想法
      

  26.   

    那你为什么不每次更换图片路径时都去生成一次图片控件呢?你想先生成图片(html控件动态生成),
    又要在服务器的后续事件(服务端)中捕获先前生成的html图片控件?如果是,这本身就不是个好的想法不好意思,少了两字