Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
4.67/5 (3 votes)
See more:
I have Created a Html Table in runtime
Using string Bulider in vb.net.
And also appended a Image source in a
Now I want that on click of that Image some events to be done.

Let I have placed Print image
and on click of that Image I want to open a new window
or whatever.

Dim s As New StringBuilder
  s.Append("<table cellspacing=0 cellpadding=4 border=1 width=100% bgcolor=#ffcocb><tr>")
        s.Append("<td colspan=1 >")
s.Append("</td>")
        s.Append("<td >")
        s.Append("<img src='images/print2.gif' border=0>")------- Image is here
        s.Append("</td>")
        s.Append("</tr></table>")


I want it to be done on the Image click.
Can C# or VB code Can Be called OnClcik .Please assist
Posted
Updated 10-Aug-12 18:34pm
v2

You need to dynamically create an onclick handler in your stringbuilder too, so that you have something like this :
s.Append("<img src='images/print2.gif' border=0 onclick='onclickhandler()'>")


of course you also need to code the onclick handler itself in your generated html code. Better try this in a normal way first and then create the string via a stringbuilder.
 
Share this answer
 
Comments
Karwa_Vivek 10-Aug-12 8:53am    
Thanks
P Johnson Durai Raj 4-Mar-17 6:05am    
how to use page bulider onlick function use wordpress but one list click?how to use function
ASP.NET
<asp:imagebutton id="ImageButton1" runat="server" onclick="ImageButton1_Click" xmlns:asp="#unknown" />


C#
protected void ImageButton1_Click(object sender, EventArgs e)
{
     MessageBox.Show("You clicked on image!");
}


Javascript =>
C#
s.Append("<img src='images/print2.gif' border='0' style='cursor: hand;' onclick='onclicked()'>");
s.Append("<script type='text/javascript'>function onclicked(){alert('You clicked on image');}</script>")


I tested & working for me =)

Hope it helps.
 
Share this answer
 
v4
Comments
Karwa_Vivek 10-Aug-12 8:42am    
I have created Whole page Dynamically using string Bulider and appending the html tags... I have not used any asp controls on the page..
Christian Amado 10-Aug-12 8:42am    
Ups. Do you need it on javascript or C# code?
Karwa_Vivek 10-Aug-12 8:44am    
javascript code can be called on onclick event of image..
Karwa_Vivek 10-Aug-12 8:53am    
Thanks I was also Thinking that only.Is working .
But One thing you must have noticed that when mouse is over the image then
its not showing any change in mouse as we see hand cursor normally.Anyways will find it .Thanks again
Christian Amado 10-Aug-12 8:55am    
Improved for you =) Regards

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900