usercontrol.ascx.cs中的Page_Load中写了一部分,用ScriptManage.RegisterStartupScript输出js代码,js中包括输出document.write()部分输出一部分东西。主页面引用了usercontrol.ascx后,输出位置跑到了页面的最下方,我怎么能控制这部分代码显示到我摆放该用户控件的位置呢?如果我直接把代码写到usercontrol.ascx中,位置虽然对了,但是又无法对其中的变量初始化了,因为貌似先输出那部分js代码。

解决方案 »

  1.   

    代码应该输出到usercontrol的位置啊。既然使用usercontrol,就没有必要使用js输出内容了,建议修改你的做法
      

  2.   

    我主页面引入usercontrol后,输入到了主页面最下方,而不是usercontrol所在位置中相对于usercontrol的最下方(绕口了。。)用户控件后台代码如下using System;
    using System.Data;
    using System.Web.UI;
    using System.Web.UI.WebControls;public partial class usercontrol_picnews : System.Web.UI.UserControl
    {
        public string piclist, namelist, urllist,swf_path;
        protected void Page_Load(object sender, EventArgs e)
        {        swf_path = "image/news.swf";
            string PicNewsList="";
            PicNewsList+="<script type=\"text/javascript\">";
            PicNewsList += "\nvar interval_time=5 ;";
            PicNewsList += "\nvar focus_width=310;";
            PicNewsList += "\nvar focus_height = 171;";
            PicNewsList += "\nvar text_height = 28;";
            PicNewsList += "\nvar text_mtop = 2;";
            PicNewsList += "\nvar text_lm = 10;";
            PicNewsList += "\nvar textmargin = text_mtop+\"|\"+text_lm;";
            PicNewsList += "\nvar textcolor = \"#2E5DB5|0xFF0000\";";
            PicNewsList += "\nvar text_align= 'left';";
            PicNewsList += "\nvar swf_height = focus_height+text_height+text_mtop; ";
            PicNewsList += "\nvar text_size = 14;";
            PicNewsList += "\nvar borderStyle=\"1|0x000000|0\";";
            PicNewsList += "\nvar pics=\"" + piclist + "\";";
            PicNewsList += "\nvar links=\"" + urllist + "\";";
            PicNewsList += "\nvar texts=\"" + namelist + "\";";        PicNewsList += "\ndocument.write('<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" width=\"'+ focus_width +'\" height=\"'+ swf_height +'\">');";
            PicNewsList += "\ndocument.write('<param name=\"allowScriptAccess\" value=\"sameDomain\"><param name=\"movie\" value=\"" + swf_path + "\"> <param name=\"quality\" value=\"high\"><param name=\"Wmode\" value=\"transparent\">');";
            PicNewsList += "\ndocument.write('<param name=\"menu\" value=\"false\"><param name=wmode value=\"opaque\">');";
            PicNewsList += "\ndocument.write('<param name=\"FlashVars\" value=\"pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'&textmargin='+textmargin+'&textcolor='+textcolor+'&borderstyle='+borderStyle+'&text_align='+text_align+'&interval_time='+interval_time+'&textsize='+text_size+'\">');";
            PicNewsList += "\ndocument.write('<embed src=\"" + swf_path + "\" wmode=\"opaque\" FlashVars=\"pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'&textmargin='+textmargin+'&textcolor='+textcolor+'&borderstyle='+borderStyle+'&text_align='+text_align+'&interval_time='+interval_time+'&textsize='+text_size+'\" menu=\"false\" bgcolor=\"#ffffff\" quality=\"high\" width=\"'+ focus_width +'\" height=\"'+ swf_height +'\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" /></embed>');  document.write('</object>'); ";
            PicNewsList += "\n</script>";
            ScriptManager.RegisterStartupScript(pn_picnews,typeof(string),"alert",PicNewsList,false);  
        }
    }
    前台空着
    主页面,仅仅是把用户控件引入,然后初始化了四个参数piclist, namelist, urllist,swf_path
    然后就到最下方了。