This is my user control example.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="add.ascx.cs" Inherits="WebApplication3.add" %>
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>
<link rel="Stylesheet" href="style.css" />
<script type="text/javascript">
function toDo()
{
//Do something
};
</script>
<asp:TextBox ID="txt_name" onkeydown="toDo()" runat="server" CssClass="input_txt"> </asp:TextBox>
When i load my page and add my user control to the page, I can not call the java script function at all. The error is:
Java script function toDo is undefined. It has really exhausted me :(
UPDATE***
My usercontrols is added to page by code. Here is the server side code to add the usercontrol to the page:
protected void lnk_new_Click(object sender, EventArgs e)
{
add add_view = LoadControl("add.ascx") as add;
Panel pnl_view = (Panel)ContentPlaceHolder1.FindControl("pnl_view");
pnl_view.Controls.Clear();
pnl_view.Controls.Add(add_view);
}
And this is the error I got:

