ASP.net用户控件无法正常运行 [英] ASP.net User Control doesn't working properly

查看:61
本文介绍了ASP.net用户控件无法正常运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为网站上的最新更新开发了一个用户控件.该控件在没有母版页的页面上正常工作.当我将控件包含到具有母版页的页面中时,它要么不加载该控件的css,要么不加载该css,则javascript代码不起作用.

应该是什么问题?需要帮助

用户控件的标记如下

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

<%@ 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>




用户控件的CodeBehind在下面




The CodeBehind for the user control is below

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;
           }




我的问题是,我应该在哪里包括CSS?我应该在用户控件或母版页或我正在使用控件的页面中添加它吗?
以及关于javascript代码的相同问题.
在此先感谢




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

推荐答案

( function (){


(' #js-news').ticker(); }); < / 脚本 > < asp:Literal ID =" runat 服务器" < >
('#js-news').ticker(); }); </script> <asp:Literal ID="lit_UpdateTicker" runat="server"></asp:Literal>




用户控件的CodeBehind在下面




The CodeBehind for the user control is below

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;
           }




我的问题是,我应该在哪里包括CSS?我应该在用户控件或母版页或我正在使用控件的页面中添加它吗?
以及关于javascript代码的相同问题.
在此先感谢




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


对于CSS,您可以使用外部CSS文件或页面级CSS或嵌入式CSS.

如果您的内容页面具有css作为外部源或页面级别,则它应位于标题中.当您添加母版页时,母版页已具有标题部分.因此,您的页面标题将变得无效,即,在html页面中仅解析了一个标题部分.

如果需要使用母版页,则将css源移动到母版页眉.
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.


这篇关于ASP.net用户控件无法正常运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆