asp.net - onClick event in VB.NET -
i programming in vb.net. trying make onclick event div tag. how can make in code behind?
one possible solution create webusercontrol panel(will rendered div) , invisible button(display:none). onclick of div click button per javascript cause automatic postback. in codebehind catch buttonclick-event , raise custom event(divclicked). can reuse control everywhere. this:
clickablediv.ascx
<%@ control language="vb" autoeventwireup="false" codebehind="clickablediv.ascx.vb" inherits="webapplication1.clickablediv" %> <asp:panel id="thediv" runat="server" onmouseover="this.style.cursor='pointer'" onclick="this.nextsibling.click()" /><asp:button id="divbutton" runat="server" />
clickablediv.ascx codebehind
partial public class clickablediv inherits system.web.ui.usercontrol public event divclicked(byval src clickablediv) private sub page_init(byval sender object, byval e system.eventargs) handles me.init me.divbutton.style.add("display", "none") end sub public readonly property div() panel return me.thediv end end property protected sub divbutton_click(byval sender object, byval e eventargs) handles divbutton.click raiseevent divclicked(me) end sub end class
and example in page(drag&drop designer):
protected sub page_load(byval sender object, byval e system.eventargs) handles me.load dim imgtest new image imgtest.imageurl = "http://skins.gmodules.com/ig/images/logos/approved/white.png" me.clickablediv1.div.controls.add(imgtest) end sub private sub clickablediv1_divclicked(byval src clickablediv) handles clickablediv1.divclicked dim div clickablediv = src end sub
btw, use __dopostback-function on div's onclick event raise postback.
Comments
Post a Comment