how to access the button content property by javascript
Last post 04-29-2008 10:06 PM by haohaoxi. 6 replies.
Sort Posts:
04-29-2008 12:49 AM
how to access the button content property by javascript

var ajaxCtrl = document.getElementById("xaml1"); //"xaml1" is the id of the whole silverlight control in the test page var button = ajaxCtrl.content.findName("MyButton"); // here i want to change the button content in silverlight // button.Content = "XXX" ....error // button.value = "XXX" ...error // i do get the instance of the button in the silverlight page // but i was blocked here // i know that the button control is differernt with the normal html control when rendered // if i use the normal html control // i can change the button "content" by // button.value = "XXX" // can any one help me on this? // thank u very much

haohaoxi

Joined on 04-16-2008
Posts 12
04-29-2008 1:59 AM
Marked as Answer
Re: how to access the button content property by javascript

Hello,

Which version of Silverlight are you using?  If you are using Silverlight 2 beta1, I think it's not possible to access the content of button from Javascript.

(If this has answered your question, please click on "Mark as Answer" on this post. Thank you!)

Best Regards,
Michael Sync

Blog : http://michaelsync.net
Feed : http://michaelsync.net/feed

mchlSync

Joined on 09-16-2005
Singapore
Posts 2,021
04-29-2008 7:22 AM
Marked as Answer
Re: how to access the button content property by javascript

thank u for u reply. the version is silverlight2 beta1. that's strange that i can set the width property while there is no way to access it's "content" property

 

haohaoxi

Joined on 04-16-2008
Posts 12
04-29-2008 9:39 AM
Re: how to access the button content property by javascript

haohaoxi:
i can set the width property
 

Width property of button?  Can you show me the code?

(If this has answered your question, please click on "Mark as Answer" on this post. Thank you!)

Best Regards,
Michael Sync

Blog : http://michaelsync.net
Feed : http://michaelsync.net/feed

mchlSync

Joined on 09-16-2005
Singapore
Posts 2,021
04-29-2008 10:31 AM
Re: how to access the button content property by javascript

en...

the code is simple:

button.width = XXX;

or just show it by:

alert(button.width);

 

that works, but i can not get the "content" property.

haohaoxi

Joined on 04-16-2008
Posts 12
04-29-2008 10:55 AM
Re: how to access the button content property by javascript

For example:

The following is Page.xaml in Silverlight 2 project.  

<UserControl
    xmlns="http://schemas.microsoft.com/client/2007"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="RET.Page"
    Width="640" Height="480">

    <Grid x:Name="LayoutRoot" Background="White" >
      
        <Button x:Name = "myBtn" Content="Button1" />
       
                  
    </Grid>
</UserControl>

Are you saying that you are able to get the width of "myBtn" one from Javascript?

For example:

function JSFunction(){
 
      myBtn.width = 10;

I don't think it would work. If it works, it's something new for me.  

(If this has answered your question, please click on "Mark as Answer" on this post. Thank you!)

Best Regards,
Michael Sync

Blog : http://michaelsync.net
Feed : http://michaelsync.net/feed

mchlSync

Joined on 09-16-2005
Singapore
Posts 2,021
04-29-2008 10:06 PM
Re: how to access the button content property by javascript

on the default test page, my javascript function is like

<script type="text/javascript">
    function ChangeButton()
    {
      var ajaxCtrl = document.getElementById("xaml1");
      var button = ajaxCtrl.content.findName("MyButton");
      button.width = 50; // this do work because i can see the width is changed when i invoke the function
                
    }
    </script>

haohaoxi

Joined on 04-16-2008
Posts 12