Export (0) Print
Expand All

HtmlInputImage.Src Property

Gets or sets the location of the image file.

[Visual Basic]
Public Property Src As String
[C#]
public string Src {get; set;}
[C++]
public: __property String* get_Src();
public: __property void set_Src(String*);
[JScript]
public function get Src() : String;
public function set Src(String);

Property Value

The location of the image file.

Remarks

Use the Src property to specify the location of the image to display in the HtmlInputImage control. If the image is not available, the text specified in the Alt property is displayed.

You can use a relative or absolute URL. A relative URL relates the location of the image to the location of the Web page without specifying a complete path on the server. The path is relative to the location of the Web page. This makes it easier to move the entire site to another directory on the server without updating the path to the image in code. You can use the relative path " ~/ " to refer to the current virtual directory where the page is located. For example, the value of Src for <input type="image" runat="server" src="~/abc/d.gif"> on a page in the "XspTest" virtual directory is <input type="image" src="/XspText/abc/d.gif">. An absolute URL provides the complete path. Therefore moving the site to another directory requires that you update the code.

Example

[Visual Basic, JScript] The following example demonstrates how to use the Src property to specify the path to an image displayed in the HtmlInputImage control.

[Visual Basic] 
<%@ Page Language="VB" AutoEventWireup="True" %>

<html>
   <script language="VB" runat=server>

      Sub SubmitBtn_Click(ByVal Source As Object, ByVal E as ImageClickEventArgs)
         Message.InnerHtml = "The Submit Button was clicked!"
      End Sub
 
      Sub ClearBtn_Click(ByVal Source As Object, ByVal E as ImageClickEventArgs)
         Message.InnerHtml = "The Clear Button was clicked!"
      End Sub

   </script>
 
   <body>

      <form method=post runat=server>

         <input type=image 
                src="Submit.jpg" 
                OnServerClick="SubmitBtn_Click" 
                runat=server>

         <input type=image 
                src="Clear.jpg" 
                OnServerClick="ClearBtn_Click" 
                runat=server>
 
         <h1> <span id="Message" runat=server></span>
         </h1>

      </form>

   </body>

</html>


[JScript] 
<%@ Page Language="JScript" AutoEventWireup="True" %>

<html>
   <script language="JSCRIPT" runat=server>

      function SubmitBtn_Click(source : Object, e : ImageClickEventArgs){
         Message.InnerHtml = "The Submit Button was clicked!"
      }
 
      function ClearBtn_Click(source : Object, e : ImageClickEventArgs){
         Message.InnerHtml = "The Clear Button was clicked!"
      }

   </script>
 
   <body>

      <form method=post runat=server>

         <input type=image 
                src="Submit.jpg" 
                OnServerClick="SubmitBtn_Click" 
                runat=server>

         <input type=image 
                src="Clear.jpg" 
                OnServerClick="ClearBtn_Click" 
                runat=server>
 
         <h1> <span id="Message" runat=server></span>
         </h1>

      </form>

   </body>

</html>

[C#, C++] No example is available for C# or C++. To view a Visual Basic or JScript example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

HtmlInputImage Class | HtmlInputImage Members | System.Web.UI.HtmlControls Namespace

Show:
© 2014 Microsoft