Hello guys. I'm trying to find out how to get properties and client methods of my controls be accessible via client scripts. For example, here is a very simple sample control:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="MyCustomControl.ascx.cs" Inherits="MyCustomControl" %>
<script type="text/javascript">
$(function() {
$("#<%=lnksave.ClientID %>").click(function() {
$("#<%=hiddenText.ClientID %>").val($("#<%=txtText.ClientID %>").val());
});
$("#<%=lnkshow.ClientID %>").click(function() {
alert($("#<%=hiddenText.ClientID %>").val());
});
});
</script>
<asp:HiddenField runat="server" ID="hiddenText" />
<input type="text" runat="server" id="txtText" />
<a id="lnksave" runat="server" href="#">Save text</a>
<a id="lnkshow" runat="server" href="#">Show text</a>
I wish another controls to access it the way like this on client side:
<%@ Register Src="~/MyCustomControl.ascx" TagName="CustomControl" TagPrefix="mycontrols" %>
...
<asp:ScriptManager runat="server" ID="scriptManager1"></asp:ScriptManager>
<div>
<mycontrols:CustomControl runat="server" ID="control1" />
</div>
...
<script type="text/javascript">
$find("<%=control1.ClientID %>").set_text("sample text");
</script>
, where set_text is something like
function(text) {
$("#<%=hiddenText.ClientID %>").val(text);
}
What kind of changes should I do to my control to get it working this way? Some code example will be very helpful. Thanks in advance!