Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
I developed a user control for latest updates in a site. The Control is working properly on a page without masterpage. When i Include that control to a page having masterpage then either it doesnot load the css for the control or if loads the css then javascript code doesnt work.

What should be the problem? Help is needed

The Markup for the usercontrol is below

XML
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="LatestUpdateTicker.ascx.cs" Inherits="LatestUpdateTicker" %>
<link href="../Css/ticker-style.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
        $(function () {
            $('#js-news').ticker();
        });
</script>
<asp:Literal ID="lit_UpdateTicker" runat="server"></asp:Literal>



The CodeBehind for the user control is below
XML
DBUtill obj = new DBUtill();
           string sql = "select * from tbl_UPDATES";
           DataTable dt = new DataTable();
           dt = obj.GetDataSet(sql).Tables[0];
           if (dt.Rows.Count != 0)
           {
               string str = "<div id=\"ticker-wrapper\" class=\"no-js\"><ul id=\"js-news\" class=\"js-hidden\">";
               foreach (DataRow dr in dt.Rows)
               {
                   str += "<li class=\"news-item\"><a href=\"" + Server.UrlPathEncode(dr["Link"].ToString()) + "\">" + dr["Title"].ToString() + "</a></li>";
                
               }
               str += "</ul></div>";
               lit_UpdateTicker.Text = str;
           }



My Question is that, Where should i include css? should i include that in the usercontrol or masterpage or the page where i am using the control.
and the same question about javascript code.
Thanks in Advance
Posted
Updated 11-Mar-11 21:15pm
v2
Comments
OriginalGriff 12-Mar-11 2:57am    
Without seeing relevant code fragments, there is not a lot we can do...
Edit your question, and try to provide more information - but don't just dump your whole program in there!

1 solution

For CSS you can use an external css file or page level css or inline css.

If your content page has css as external source or page level then it should be at the header. When you add the master page, the master page already have header section. So your page header become invalid, i.e only one header section is parsed in a html page.

If you need to use master page then move the css sources to the master page header.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900