How to acess html control in C# code behind


  • I am using




    img runat="server" alt="hi" src="star1.gif" name="img1" border="0" onmouseover="ChangeImg()" onclick="Show"/>

    i want the click event for <img> html tag

    Thanks in advance...!

    Friday, June 11, 2010 1:02 PM


All replies

  • If you want a post back event then it is better to use server controls. If you have any requirements to use html controls then you need to invoke postback through java script in the following way:

    Use onclick event (onclick="show()") to call Javascript function and do postback from that function.

    • Marked as answer by Harry Zhu Friday, June 18, 2010 5:30 AM
    Monday, June 14, 2010 6:56 AM
  • Hi,

    For the
    questions relating to ,please post to:


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Friday, June 18, 2010 5:33 AM
  • Use the following code. to catch it on code behind.


    img runat="server" alt="hi" src="star1.gif" id="img1" border="0" onmouseover="ChangeImg()"/>

    System.Web.UI.HtmlControls.HtmlGenericControl HtmlIMG;

    HtmlIMG = (HtmlGenericControl) FindControl("img1");

    Assign to HtmlIMG object on code behind what you need to display on img1. this would work.


    You can contact Vofox Solutions for more help, which i used to take for my development needs.


    Thursday, June 24, 2010 6:19 AM
  •  hi

      in this case u can take one server button control and hide it using style="display:none". Call javascript function i.e show

    javascript code as per below.

    function show()


     var buttonControl=document.getElementById (button id)


    and write your code inside button click event in code behind. In this way you can handle click event for image



    Thursday, July 01, 2010 7:31 AM