asp.net - UserControl Raise Events -
i add onfocus event web user control (.ascx) expection raise event when gets focus doesn't. not intended work way , how can raise event? here sample below, doesn't work.
<%@ control language="vb" autoeventwireup="false" codebehind="webusercontrol1.ascx.vb" inherits="raiseeventusercontrol.webusercontrol1" %> <div style="padding: 5px; background-color: #c0c0c0"> tb1: <asp:textbox id="textbox1" runat="server"></asp:textbox> <br /> <br /> tb2: <asp:textbox id="textbox2" runat="server"></asp:textbox> </div> <%@ register src="webusercontrol1.ascx" tagname="webusercontrol1" tagprefix="uc1" %> <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script type="text/javascript"> function raiseevent(obj) { alert("event raised for: " + obj.id) } </script> </head> <body> <form id="form1" runat="server"> <div> <uc1:webusercontrol1 id="webusercontrol11" runat="server" onfocus="raiseevent(this)" /> <br /> <uc1:webusercontrol1 id="webusercontrol12" runat="server" onfocus="raiseevent(this)" /> </div> </form> </body> </html>
this can achieved using jquery. in head element, add following:
<script type="text/javascript" src="http://code.jquery.com/jquery-1.5.js"></script> <script type="text/javascript"> $(document).ready(function(){ $('input[name^="webusercontrol"]').focusin(function () { $(this).val("i have focus"); }); }); </script>
what is, grabs input elements name starts "webusercontrol" , adds "got focus" event. handler event places "i have focus" value input element.
Comments
Post a Comment