我的Silverlight 4应用无法运行Page_Load [英] My Silverlight 4 app does not run Page_Load

查看:73
本文介绍了我的Silverlight 4应用无法运行Page_Load的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个Silverlight 4应用程序.我试图加载initParams以传递到浏览器外应用程序. Page_Load永远不会运行.

我的aspx文件包括以下内容:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="PackageInTestPage.aspx.cs" Inherits="PackageIn.Web.PackageInTestPage" %>
…
<body>
    <form id="form1"  runat="server" style="height:100%">
    <div id="silverlightControlHost">
        <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
…
          <param name="initParams" value="<% =WebDotConfig%>" /></div>



我的代码隐藏文件PackageInTestPage.aspx.cs看起来像这样:

 命名空间 PackageIn.Web
{
    公共 部分  class  PackageInTestPage:System.Web .UI.页面
    {
        公共 字符串 WebDotConfig { get ; 设置; }
        // 此代码似乎无法运行
        受保护的 无效 Page_Load(对象发​​件人,EventArgs e)
        {
            WebDotConfig = " 
            < code to = "  fill = " " "  " webdotconfig =  " </ 代码 >  



我也尝试将以下代码添加到.aspx文件,但没有运气:

 <  脚本   类型  ="    语言  ="  c#" > 
    公用字符串WebDotConfig {放; }
    受保护的void Page_Load(对象发送者,EventArgs e)
    {
        WebDotConfig ="PackageWeight1 =" + ConfigurationManager.AppSettings ["PackageWeight1"];
        WebDotConfig + =,TicketCount1 =" + ConfigurationManager.AppSettings ["TicketCount1"];
        WebDotConfig + =,MaxTicketsPerPackage =" + ConfigurationManager.AppSettings ["MaxTicketsPerPackage"];
    } 





该应用程序将运行,但initParams始终为空.
我尝试将"throw new exception("xxx");"插入到Page_Load的第一行中,这没有什么区别,因此我不认为Page_Load已运行.在调试器中,断点显示为!"说断点将永远不会到达.
无论我是否用尽浏览器,都是一样的.如果将PackageIn.Web项目设置为启动项目,则Page_Load将运行.

我已经尝试了codebehind =和heriters =值的一些变体,但这没有帮助.

我已经阅读了多篇文章,描述了如何在Silverlight中设置initParams ,我想我正在按照所有说明进行操作.
如果有人可以告诉我我在做什么错或如何找到问题,我将非常感激.

解决方案

现在可以使用了.我认为问题是我在服务器上使用了initParams(lcase i),在客户端上使用了InitParams(ucase I).它似乎没有运行,因为我需要将PackageIn.Web设置为启动项目.


这是为了标记已解决问题的文本


I have written a Silverlight 4 app. I tried to load initParams to pass to the out-of-browser app. Page_Load is never run.

My aspx file includes the following:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="PackageInTestPage.aspx.cs" Inherits="PackageIn.Web.PackageInTestPage" %>
…
<body>
    <form id="form1"  runat="server" style="height:100%">
    <div id="silverlightControlHost">
        <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
…
          <param name="initParams" value="<% =WebDotConfig%>" /></div>



My codebehind file, PackageInTestPage.aspx.cs looks like this:

namespace PackageIn.Web
{
    public partial class PackageInTestPage : System.Web.UI.Page
    {
        public string WebDotConfig { get; set; }
        //This code does not appear to run
        protected void Page_Load(object sender, EventArgs e)
        {
            WebDotConfig = ""
            <code to="" fill="" in="" webdotconfig="">
            ...
</code>



I also tried adding the following code to the .aspx file with no luck:

<script type="text/C#" language="c#" >
    public string WebDotConfig { get; set; }
    protected void Page_Load(object sender, EventArgs e)
    {
        WebDotConfig  = "PackageWeight1=" + ConfigurationManager.AppSettings["PackageWeight1"];
        WebDotConfig += ",TicketCount1=" + ConfigurationManager.AppSettings["TicketCount1"];
        WebDotConfig += ",MaxTicketsPerPackage=" + ConfigurationManager.AppSettings["MaxTicketsPerPackage"];
    }





The app will run but the initParams is always blank.
I tried inserting "throw new exception("xxx");" into the first line of Page_Load and it made no difference so I don''t think the Page_Load was run. In the debugger, the breakpoint displays with the "!" saying the breakpoint will never be reached.
It is the same whether I run out-of-browser or not. If I set my PackageIn.Web project as the start up project, THEN the Page_Load will run.

I have tried a few variations in the codebehind= and inherits= values but that has not helped.

I have read multiple posts describing how to set initParams in Silverlight and I think I am following all the instructions.

If anyone can tell me what I am doing wrong or how to track down the problem, I would really appreciate it.

解决方案

This works now. I think the problem was I was using initParams (lcase i) on server and InitParams (ucase I) on client. It appeared to be not running because I needed to set PackageIn.Web as start up project.


This is text is just to mark the problem solved


这篇关于我的Silverlight 4应用无法运行Page_Load的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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