User-2019299038 posted
Hi all,
I've read several posts which all point to ClientIDMode, however, unless I'm just too sleepy, I can't seem to understand why I can't get at my UserControl from javascript. Here's the user control markup. The code-behind just has an empty Page_Load block.
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl1.ascx.cs" Inherits="UserControlTest.WebUserControl1" %>
<asp:Table ID="Table1" runat="server">
<asp:TableRow>
<asp:TableCell>
<asp:TextBox ID="TextBox1" runat="server">
</asp:TextBox>
</asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="TextBox2" runat="server" Rows="5">
</asp:TextBox>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
Here is the markup for Default.aspx, the code-behind for this page is practically empty as well.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="UserControlTest.Default" %>
<%@ Register Src="~/WebUserControl1.ascx" TagName="WebUserControl1" TagPrefix="uc" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script type="text/javascript">
function OnClick() {
var _uc = document.getElementById('WebUserControl1');
alert(_uc === null); // always true
}
</script>
<title>
</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<uc:WebUserControl1 ID="WebUserControl1" runat="server" ClientIDMode="Static" />
<asp:HyperLink ID="HyperLink1" runat="server" Text="Click" NavigateUrl="javascript:OnClick()"></asp:HyperLink>
</div>
</form>
</body>
</html>
What am I missing?