A project was created a few days ago, and the database information was read on the page. XAML page of Silverlight. the login information was transferred to the ASPX page, which involved the interaction between Silverlight and ASP. NET.
Public static string userpassword; <br/> Public static string userid; <br/> Public static string roleid; <br/> htmlwindow html = htmlpage. window; <br/> // select a person to read personnel information <br/> private void comuser_selectionchanged (Object sender, telerik. windows. controls. selectionchangedeventargs e) <br/>{< br/> If (comuser. selectedvalue! = NULL) <br/>{< br/> wcfserviceclient clientinfo = new wcfserviceclient (); <br/> clientinfo. getuserinfocompleted + = new eventhandler <getuserinfocompletedeventargs> (clientinfo_getuserinfocompletedeventargs); <br/> clientinfo. getuserinfoasync (comuser. selectedvalue. tostring (); <br/>}< br/> // record the logon information of a person <br/> void clientinfo_getuserinfocompletedeventargs (Object sender, getuserinfocompletedeventargs E) <br/>{< br/> If (E. error = NULL) <br/>{< br/> foreach (VAR its in E. result) // E. result is the returned value from the WCF Service <br/>{< br/> userpassword = its. password; <br/> userid = its. userid. tostring (); <br/> roleid = its. roleid. tostring (); <br/>}< br/> else <br/>{< br/> HTML. alert (errormessage); <br/>}< br/>}
Here, we will pass the userid and roleid values to An ASPX page and convert them into logon session variables. How can we solve this problem!
Here we use a simple method.
// Log on to the system and record the login personnel ID. <br/> private void btnlogin_click (Object sender, routedeventargs e) <br/>{< br/> If (txtpassword. password = userpassword) <br/>{< br/> string url = "http: // localhost: 24690/mastermain. aspx? Userid = "+ userid +" & roleid = "+ roleid; <br/> HTML. navigate (New uri (URL); <br/>}< br/> else <br/>{< br/> string message = "friendly warning: Incorrect password! Please verify! "; <Br/> html. Alert (Message); <br/>}< br/>}
How can we solve this problem if we want to pass the value in aspx to the pages in the Silverlight XAML? Here is an idea!
The initparameter can be passed in silverlight2, but the method changed in sl3:
<Param name = "initparams" value = "Path = generatedimages/dzc_output.xml, zoomin = 3"/>
App. XAML. CS
If (E. initparams! = NULL)
{
Foreach (VAR data in E. initparams)
{
.....
}
}
The following method can also be used:
Directly include the parameter: <input type = "hidden" id = "youparaname" name = "youparaname" value = "youparavalue">
Then in SL: htmlpage. Document. getelementbyid ("youparaname"). getattribute ("value ")
This is convenient, easy to understand, and easy to post to the server.