如何触发使用String Builder(HTML)创建的对象的事件 [英] how to fire Event of Objects Created with String Builder(HTML)
本文介绍了如何触发使用String Builder(HTML)创建的对象的事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在运行时创建了一个HTML表
在vb.net中使用字符串Bulider.
并且还在
中附加了Image源.现在,我希望在单击该Image时完成一些事件. 让我放置打印图像" 然后单击该图像,我想打开一个新窗口 等等. I have Created a Html Table in runtime
|
推荐答案
您需要动态创建您的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屋!
查看全文