Hi
How do I declare a variable with a value from a database. What I want to do is when the user logs in that I get the primary key that is associated with the user name. Once I have the id what I want to do is when they click on the row in a database that it adds a records using that primary key.
Loading
Andy DominguezPosted Feb 17, 2011, 3:45 PM
With this attribute, you can now use ASP.NET Session in your service. Now create a class which is marked as DataContract and its properties marked as DataMember, so this object can be serialized and sent to client:
[DataContract]
public class MyObject
{
[DataMember]
public string Name { get; set; }
[DataMember]
public int Age { get; set; }
}
In your ASP.NET page's code behind, create such an object and store it in Session. Note you must do so in Page.Load or an earlier event or the Session variable may not be ready when you invoking the web service:
protected void Page_Load(object sender, EventArgs e)
{
HttpContext.Current.Session["MySessionObject"] = new MyObject() { Name = "Lante", Age = 23 };
}
In the service method, you return this Session object:
[OperationContract]
public MyObject DoWork()
{
return (MyObject)HttpContext.Current.Session["MySessionObject"];
}
Now add a service reference in your Silverlight project, and call the web service:
public Page()
{
InitializeComponent();
ServiceClient client = new ServiceClient();
client.DoWorkCompleted += new EventHandler
client.DoWorkAsync();
}
Suthish NairPosted Feb 17, 2011, 2:49 PM
You will get articles with examples.
Andy DominguezPosted Feb 17, 2011, 11:14 AM
Thanks for replying. I have been looking on the session thing but I am not understanding how to set this up. Do I have to have a textbox on the form to get the value that I want? The other problem I am having is that i have been reading that this only works for text and nothing else is that true?
Suthish NairPosted Feb 16, 2011, 12:49 PM
Search for articles here.