When i use the below code in webpage (.aspx file), it works fine; but when I use the below in a user control (.ascx file) it does not work.
How to fix this? Do i have to do any modifications in the masterpage.
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ExclusionSwipeCardRequest.ascx.cs" Inherits="ExclusionSwipeCardRequest" %>
<link type="text/css" rel="stylesheet" href="../App_Themes/LMSTheme/jquery-ui-1.8.16.custom.css" />
<script type="text/javascript" src="../Scripts/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="../Scripts/jquery-ui-1.8.16.custom.min.js"></script>
<script type="text/javascript" language="javascript">
$(function() {
$("#txtFromDate").datepicker({ dateFormat: 'mm-dd-yy', changeMonth: true, changeYear: true });
});
</script>
<asp:TextBox ID="txtFromDate" MaxLength="10" runat="server" autocomplete="off" ToolTip="Enter Fr开发者_JAVA技巧om Date"></asp:TextBox>
the id for the textbox is not correct,
try
$("#<%=txtFromDate.ClientID%>").datepicker({ dateFormat: 'mm-dd-yy', changeMonth: true, changeYear: true });
instead of
$("#txtFromDate").datepicker({ dateFormat: 'mm-dd-yy', changeMonth: true, changeYear: true });
I might suggest that your paths have changed, which would mean that the src
/href
value of the script/CSS imports are wrong.
Rather than using relative paths that jump up directories, you could try qualifying the path from the root of the website (starting the URL with a forward-slash /
), such that:
<link type="text/css" rel="stylesheet" href="/Scripts/App_Themes/LMSTheme/jquery-ui-1.8.16.custom.css" />
<script type="text/javascript" src="/Scripts/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="/Scripts/jquery-ui-1.8.16.custom.min.js"></script>
Obviously if there are any paths between the root and the Scripts
folder, you would need to specify it, for example:
src="/MyIntermediatePath/Scripts/jquery-1.6.2.min.js"
Also worth mentioning is that although control ID prefixing can be managed (even turned off in .NET4), generally server-side controls have IDs in the page that have been concocted by their parent container, such as:
txtFromDate -> ctl001_txtFromDate
If you weren't using a server-side control in the page initially, you might want to check you haven't introduced an issue with jQuery finding the control in the rendered page.
the problem is the src url in your script references. it's relative to the page's location where control is used, not the control itself.
I recommend you put your css/script links in the [master]page instead of user control.
精彩评论