如何触发使用String Builder(HTML)创建的对象的事件 [英] how to fire Event of Objects Created with String Builder(HTML)

查看:81
本文介绍了如何触发使用String Builder(HTML)创建的对象的事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在运行时创建了一个HTML表
在vb.net中使用字符串Bulider.
并且还在

中附加了Image源.现在,我希望在单击该Image时完成一些事件.

让我放置打印图像"
然后单击该图像,我想打开一个新窗口
等等.

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>")



我希望在图像"点击上完成该操作.
可以将C#或VB代码称为OnClcik吗.请协助



I want it to be done on the Image click.
Can C# or VB code Can Be called OnClcik .Please assist

推荐答案

您需要动态创建您的stringbuilder中也有一个onclick处理程序,这样您就可以得到这样的内容:
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()''>")



当然,您还需要在生成的html代码中对onclick处理程序本身进行编码.最好先以常规方式尝试此操作,然后再通过stringbuilder创建字符串.



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.


<asp:imagebutton id="ImageButton1" runat="server" onclick="ImageButton1_Click" xmlns:asp="#unknown" />





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



Javascript =>



Javascript =>

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.


这篇关于如何触发使用String Builder(HTML)创建的对象的事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆