|
|||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
Note: This is an unedited contribution. If this article is inappropriate,
needs attention or copies someone else's work without reference then please
Report This Article
IntroductionAfter posting an small article about how to create password box in Silverlight 2 beta 2 I have got a one request about usage of pure html password input instead of TextBox from Silverlight. I thought that this could be useful to present also how to sent objects from html page through javascripts into Silverlight page. Using the codeTo establish communication with Silverlight page we have to do two easy things. Mark with special attribute name an method or a whole class that it will be accessed via javascript and then register a instance of this class. public partial class Page : UserControl
{
public Page()
{
InitializeComponent();
HtmlPage.RegisterScriptableObject("loginProvider", this);
}
[ScriptableMember()]
public void Login(string password, string login)
{
this.Message.Text = "Your login is: " + login +
"\r\nFirst letter of your password is: " + (password.Length > 0 ? password[0].ToString() : "");
}
}
Second thing is to create a html code which will be responsible for collecting data from the entry form and send it to Silverlight control. For this purpose we have created <script type="text/javascript">
function invokeManagedCode(){
var form = document.getElementById("loginpanel");
var password = form.password.value;
var user = form.user.value;
var control = document.getElementById("sl2b2");
control.Content.loginProvider.Login(password,user);
}
</script>
</head>
<body>
<form id="loginpanel" name="input" ACTION="javascript:invokeManagedCode()">
Username:
<input type="text" name="user">
Password:
<input type="password" name="password">
<input type="Submit" value="Login" >
Points of InterestFor sure communication between html content and Siliverlight can be done in several ways. This is only one of them. HistoryKeep a running update of any changes or improvements you've made here.
|
||||||||||||||||||||||||||||||||||||||||||||