click event of html image control

Posted by Klbaiju under ASP.NET on 8/13/2010 | Views : 23040 | Status : [Member] | Replies : 2
Hi,
iam using an html imagecontrol ,i want to write the click event in .cs page

<img alt="image" src="Images/officeoperation/cal.gif" runat="server" onclick="img1_onclick" />

.cs code

public void img1_onclick(object sender, EventArgs e)
{

Button1.Text = "Image";

}
it is not working


Any solution

Regards
K L BAIJU




Responses

Posted by: Raja on: 8/13/2010 [Member] Starter

Up
0
Down
Normally its not possible to call the server side event from html control by specifying the runat="server". In this case you should be using <asp:Image> control something like this.

//aspx page

<asp:ImageButton ID="ImageButton1" runat="server"
ImageUrl="~/4-Tier/images/list4-tier.GIF" onclick="ImageButton1_Click" />

//code behing
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{

}


Or call a javascript function that will internally call the server side event (PageMethod). Look at this http://www.dotnetfunda.com/articles/article454-using-pagemethods-and-json-in-aspnet-ajax.aspx

Hope it will help

Regards,
Raja, USA

Klbaiju, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Shankul2784 on: 8/13/2010 [Member] Bronze

Up
0
Down
Hi,


Other way is -

<asp:linkbutton id="link1" runat="server" onclick="link1_onclick">
<img alt="image" src="Images/officeoperation/cal.gif" runat="server" />
<asp:LinkButton />

Thanks & Regards,

Shailesh

Klbaiju, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response