Skip to main content

Microsoft Silverlight

Answered Question SilverLight InitParamsRSS Feed

(0)

maorb
maorb

Member

Member

0 points

4 Posts

SilverLight InitParams

Hi,

 

in the <asp:Silverlight ID="Xaml1"> control we have

 we have initparams by Xaml1.InitParameters.

How can i access to init params by the html, in :

div id="silverlightControlHost">

<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">

<param name="source" value="ClientBin/SilverlightApplication2.xap"/>

<param name="onerror" value="onSilverlightError" />

<param name="background" value="white" />

<param name="minRuntimeVersion" value="3.0.40307.0" />

<param name="autoUpgrade" value="true" />

<a href="http://go.microsoft.com/fwlink/?LinkID=141205" style="text-decoration: none;">

<img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/>

</a>

</object>

<iframe style='visibility:hidden;height:0;width:0;border:0px'></iframe>

</div>

??

 

Thanks

 

kranthi.gullapalli
kranthi....

Member

Member

237 points

42 Posts

Re: SilverLight InitParams

<param name="initParams" value="Param1=Param1Value,Param2=Param2Value" />

-Thanks
Kranthi

.netdan
.netdan

Contributor

Contributor

3368 points

511 Posts

Re: SilverLight InitParams

Hi,

You simply add the following param to the existing ones:

<param name="InitParameters" value="param1=Hello,param2=World" />

So your full HTML would look like:

<object id="silverClient" data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
	<param name="source" value="ClientBin/SilverClient.xap"/>
	<param name="onerror" value="onSilverlightError" />
	<param name="background" value="#00ffffff" />
	<param name="minRuntimeVersion" value="2.0.30923.0" />
	<param name="autoUpgrade" value="true" />
	<param name="InitParameters" value="param1=Hello,param2=World" />
	<a href="http://go.microsoft.com/fwlink/?LinkID=124807" style="text-decoration: none;">
		<img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/>
	</a>
</object>

There is a good article here http://www.silverlightshow.net/tips/How-to-pass-initialize-parameters-to-Silverlight-application-using-ASP.NET-3.5-Silverlight-control.aspx showing you how to get them in your Silverlight application.

Remember to click "Answer" if this has helped you!

Dan Birch
MCSD, MCAD, MCP
Free Silverlight Controls | Free .NET Silverlight CMS

maorb
maorb

Member

Member

0 points

4 Posts

Re: SilverLight InitParams

Hi,

Thanks, but my parameter is not static. i need to set him dynamic.

 for example in the aspx:

Xaml1.InitParameters = "";

 

Thanks

.netdan
.netdan

Contributor

Contributor

3368 points

511 Posts

Re: SilverLight InitParams

Hi,

To helps us understand your problem, what are you working in ASP.NET, HTML or Silverlight?

Remember to click "Answer" if this has helped you!

Dan Birch
MCSD, MCAD, MCP
Free Silverlight Controls | Free .NET Silverlight CMS

maorb
maorb

Member

Member

0 points

4 Posts

Re: SilverLight InitParams

Hi,

I'm working with silverLight.

but i want to know how i'm set the init params dynamicly.

.netdan
.netdan

Contributor

Contributor

3368 points

511 Posts

Re: SilverLight InitParams

Your working in Silverlight, are you trying to set the InitParameters in Silverlight or something else like javascript, HTML, ASP.NET? It is this that is confusing me as I couldn't see any reason to set the init params in Silverlight.

Remember to click "Answer" if this has helped you!

Dan Birch
MCSD, MCAD, MCP
Free Silverlight Controls | Free .NET Silverlight CMS

MarkMonster
MarkMonster

Contributor

Contributor

5220 points

1,046 Posts

Answered Question

Re: SilverLight InitParams

I've written an article about how you can restart your Siverlight Application using Javascript. Restarting the Silverlight Object with different initParams from within Silverlight

Mark Monster - MCPD Enterprise
http://mark.mymonster.nl
Silverlight and Expression Insiders UG

Dont forget to click "Mark as Answer" on the post that helped you.

ssawchenko
ssawchenko

Member

Member

342 points

177 Posts

Re: SilverLight InitParams

Couldn't you inject the dynamic parameters the same way you would with any other html code?

[My syntax may be wrong since I've only done a little ASP years and years ago]:

<param name="InitParameters" value="param1=<%=myparam1 %>, param2=<%=myParam2 %>" />

 

MarkMonster
MarkMonster

Contributor

Contributor

5220 points

1,046 Posts

Re: SilverLight InitParams

This mechanism would work as well. But this is from Server Side code. I though he wanted to control this from a Silverlight application. In that case you would only be able to make use of Javascript to control the initParams.

Mark Monster - MCPD Enterprise
http://mark.mymonster.nl
Silverlight and Expression Insiders UG

Dont forget to click "Mark as Answer" on the post that helped you.

pkr2000
pkr2000

Participant

Participant

1219 points

377 Posts

Re: SilverLight InitParams

Just to be clear, isn't the param called "InitParams" and not "InitParameters"?

I'm posting because I've just spent 5 mins scratching my head wondering why I couldn't see any values!

 

 

MarkMonster
MarkMonster

Contributor

Contributor

5220 points

1,046 Posts

Re: SilverLight InitParams

You're correct, it's called InitParams, just like I mention in my article: http://mark.mymonster.nl/2008/12/22/restarting-the-silverlight-object-with-different-initparams-from-within-silverlight/

Mark Monster - MCPD Enterprise
http://mark.mymonster.nl
Silverlight and Expression Insiders UG

Dont forget to click "Mark as Answer" on the post that helped you.

nirav_2052003
nirav_20...

Member

Member

274 points

105 Posts

Re: SilverLight InitParams

Hi,

I like to suggest you to add HTML stuff for silverlgiht using an HTML file template or rendering html for silverlight using string builder.

For example following is your HTML for silverlight control.

<object id="silverClient" data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
	<param name="source" value="ClientBin/SilverClient.xap"/>
<param name="InitParameters" value="param1=Hello,param2=World" />
	<param name="onerror" value="onSilverlightError" />
	<param name="background" value="#00ffffff" />
	<param name="minRuntimeVersion" value="2.0.30923.0" />
	<param name="autoUpgrade" value="true" />
	<param name="InitParameters" value="param1=Hello,param2=World" />
	<a href="http://go.microsoft.com/fwlink/?LinkID=124807" style="text-decoration: none;">
		<img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/>
	</a>
</object>
If you write above html programmatically, you can write InitParameters values programatically.

pkr2000
pkr2000

Participant

Participant

1219 points

377 Posts

Re: SilverLight InitParams

nirav_2052003:

Hi,

I like to suggest you to add HTML stuff for silverlgiht using an HTML file template or rendering html for silverlight using string builder.

Isn't that the same as .netdan suggested? (and it's not InitParameters in HTML and you've added twice).

 

avtar
avtar

Member

Member

63 points

69 Posts

Re: Re: SilverLight InitParams

Hi,

I have same problem with SilverLight InitParams.

 Earlier we are using 

 <form ID="Xaml1" runat="server" style="height:100%;">
        <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
        <div  style="height:100%;">
            <asp:Silverlight ID="Silverlight1" runat="server" Source="~/ClientBin/Shell.xap"
              InitParameters="key1=value1,key2=value2"
               MinimumVersion="3.0.40307.0" Width="100%" Height="100%" />
        </div>
    </form>

 and able to set InitParameters value in code behind like this.

protected void Page_Load(object sender, EventArgs e)
    {  

  Silverlight1.InitParameters = "userID=" + this.User.Identity.Name + ", SVCAddress=" +                                        ConfigurationManager.AppSettings["DashboardSVCAddress"].ToString();       
    }

 

Now I am using the silverlight release version 3.0 but unable to set InitParam from code behind.

 Following is the code of my Main.aspx

 <form id="form1" runat="server" style="height:100%">
    <div id="silverlightControlHost">
        <object id="SilverlightObjcet" data="data:application/x-silverlight-2,"  type="application/x-silverlight-2" width="100%" height="100%">
          <param name="source" value="~/ClientBin/Shell.xap"/>
          <param name="onError" value="onSilverlightError" />
          <param name="InitParameters" value="key1=value1,key2=value2" />
          <param name="background" value="white" />
          <param name="minRuntimeVersion" value="3.0.40624.0" />
          <param name="autoUpgrade" value="true" />
          <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40624.0" style="text-decoration:none">
               <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style:none"/>
          </a>
        </object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe></div>
    </form>

 

And one more doubt, after this new release do we not use <form id="form1" runat="server" style="height:100%">
    <div id="silverlightControlHost">
        <object id="SilverlightObjcet" data="data:application/x-silverlight-2,"  type="application/x-silverlight-2" width="100%" height="100%">
          <param name="source" value="~/ClientBin/Shell.xap"/>
          <param name="onError" value="onSilverlightError" />
          <param name="InitParameters" value="key1=value1,key2=value2" />
          <param name="background" value="white" />
          <param name="minRuntimeVersion" value="3.0.40624.0" />
          <param name="autoUpgrade" value="true" />
          <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40624.0" style="text-decoration:none">
               <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style:none"/>
          </a>
        </object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe></div>
    </form>

 

One more doubt in latest version of silverlight (3.0) do we not used system.web.silverlight.dll

 Thanks lot.

Please click on "Mark As Answer", if this answered your query partially or fully.

mepfuso
mepfuso

Member

Member

683 points

151 Posts

Re: Re: SilverLight InitParams

You can do in your .aspx file:

 

<param runat="server" name="initParams" id="prmInitParams" />   
  

And in your code in the behind in the Page_Load Event for example:

 

this.prmInitParams.Attributes["value"] = myInitParamsString;
 

...: Between the iron gates of fate, the seeds of time were sown :...

CoreBruton
CoreBruton

Member

Member

86 points

20 Posts

Re: Re: SilverLight InitParams

Here's a cleaned up example of passing values to your silverlight app at runtime.

 

Master page:

<uc3:mycontrol ID="SLControl" runat="server" height="175" width="700" itemname="Main" />

User control:

<param name="Width" value="<%=width %>" />

<param name="Height" value="<%=height %>" />

<param name="InitParams" value="<%=InitParams %>" />

User control code:

Public Property width() As integer

Public Property height() As Integer

Public ReadOnly Property InitParams() As String

Please "Mark as Answer" if this post answered your question. :)

beaphy
beaphy

Member

Member

8 points

9 Posts

Re: Re: SilverLight InitParams

Hi All,

I hope things are a sunny around the world as it is here! 

I have this working on the DEV machine, but ALAS, it doesn't work when I deploy it.

 So, just to back track, what I have done is this.

//aspx

<asp:Silverlight ID="Xaml1" runat="server" InitParameters="" Source="~/ClientBin/BNA_BTSNetApps.xap" Windowless="true" MinimumVersion="2.0.31005.0" Width="100%" Height="100%" />

 //hosting aspx.cs file code behing

protected string InitParams { get; private set; }
protected void Page_Load(object sender, EventArgs e)
{
    if (Page.IsPostBack) return;
   
if (Convert.ToString(System.Web.HttpContext.Current.User.Identity.Name).Length > 0)
    {
// set the local identity name
            Xaml1.InitParameters = "UserIdentity=" + System.Web.HttpContext.Current.User.Identity.Name;
    }
   
else
   
{
            Xaml1.InitParameters =
"UserIdentity=NotWorking";
    }
}

 //catch it in the app.cs Application_StartUp

string thisIsTheWindowsAccount = string.Empty;
foreach (String key in e.InitParams.Keys)
{
   
if (key == "UserIdentity")
    {
         
thisIsTheWindowsAccount = e.InitParams[key];
    }
}
this.RootVisual = new BTS_Logon(thisIsTheWindowsAccount);

//and I get sent the "NotWorking" string... Is this due to the crossdomain policy of some type?

#### #### #### EDIT #### #### ####

I found this that more or less says it can't be done unless using a caching method with "Outof Browser", but if anyone could explain this further that would be awesome. Cheers

 #### #### #### EDIT #### #### ####

 Just another update, now using the following and involking from the silverlight app, the IP address will just have to do for now

<script language="javascript" type="text/javascript">
function getClientIp() {
return '<%= Request.ServerVariables["REMOTE_ADDR"] %>';
}
</script>

pkr2000
pkr2000

Participant

Participant

1219 points

377 Posts

Re: Re: SilverLight InitParams

No, don't use the asp:silverlight control, use the object tag as everyone has posted.

beaphy
beaphy

Member

Member

8 points

9 Posts

Re: Re: SilverLight InitParams

And how does using this change the fact of getting the computer name?

pkr2000
pkr2000

Participant

Participant

1219 points

377 Posts

Re: Re: SilverLight InitParams

It doesn't but why bang your head againsts a wall using what amounts to an unsupported tag, plus IMO it's just complicating the problem as you're having to second guess how the design time form of the asp control is interpreting its properties. Just remove all that guess work.

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities