Skip to main content
Home Forums Silverlight Programming Programming with .NET - General How to Submit or POST a ASP.NET page from a Silverlight Application
10 replies. Latest Post by .netdan on April 3, 2009.
(0)
amurawat...
Member
0 points
4 Posts
03-29-2009 10:56 PM |
I have an ASP.NET page that has two forms of which one form has a silverlight control placed. I want to submit (POST) the second form in the same page from Silverlight. Please can some one tell me how to do it. I tried HtmlDoc.Submit("secondFomrName") but it submits/postbacks the entire page as a result my first form which has the silverlight control is also posted and it resets. I only want the second form to get refreshed or posted.
Here the code snippet of what im trying to do...
The code on my HTML Page.
<
<ContentTemplate>--
</asp:UpdatePanel>--
</
The code on my silverlight app from where i want to submit the second form on my page.
HtmlDocument doc = HtmlPage.Document;
doc.Submit(
muthu.v
438 points
87 Posts
03-30-2009 2:10 AM |
I remember this. As far as I can tell, though the UpdatePanel updates only the panel called, it usually reloads the entire page again. That is the whole page is sent to the server and only the modifiable elements are changed.
The rest of the page is kept intact and sent back to the client. Unfortunately with Silverlight if this happens the control is reloaded.
So you can possibly use a GET parameter method to invoke the URL to do whatever you want. Otherwise you can have some hidden controls in your page with your values to maintain your state and then when the page reloads, read all of them back and restore the silverlight control state.
But if you find a different solution to this problem, let me know as well.
Muthu
mepfuso
683 points
153 Posts
03-30-2009 5:54 AM |
If you just want to send stuff to the server, and you can and want to update things in your page programmatically in javascript, there seem to be ways doing so.
Using Microsoft's ASP.NET Ajax, you could use a WebMethod in your aspx Code behind:
http://msdn.microsoft.com/en-us/library/byxd99hx(VS.71).aspx
This is turned to a javascript function on the client side.
When you are using other great client script libraries like jQuery or ExtJs at http://www.extjs.com - these support a syntax from javascript that goes something like
Ext.Ajax.request(myUrl, ...);
Such a client side function or 'microsoft web method' you then call from silverlight by creating an instance of it:
http://timheuer.com/blog/archive/2008/03/09/calling-javascript-functions-from-silverlight-2.aspx
03-30-2009 1:39 PM |
I tried the GET option as well but it did not work.
03-30-2009 8:07 PM |
I think you might have used the same page for doing the query. The moment you use the same page, the silverlight control is reborn.
So use another aspx page and invoke it using GET as we discussed before.
jackbond
Contributor
2820 points
725 Posts
03-31-2009 1:54 AM |
Have you considered implementing a web service to relay the information you are attempting to post back? HTML forms and UpdatePanels are old school hacks. :)
03-31-2009 1:40 PM |
Not sure what you mean by using the WS to relay service.... Can you please give me some pointers...
.netdan
3392 points
513 Posts
03-31-2009 7:53 PM |
Hi, The information you will be collecting in the second form, could it be done in a Silverlight application? If not, does the data have to be posted back using a form?
03-31-2009 10:30 PM |
amurawatSilver:Not sure what you mean by using the WS to relay service
HTML forms = Old/horrible way of transferring data over HTTP
Web services = New/efficient way of transferring data over HTTP
What it sounds like you are trying to do is transfer data back to the server, process it a bit, send a response back, and update the UI. Instead of focusing on getting the form submitted, try adding a web service to your ASP.NET solution, and then using that to transfer your data. There are plenty of samples here of how to do that. Good luck.
04-03-2009 4:10 PM |
What im trying to do here is call a web service... Get the data from the WS and display it on the html page on the MouseLeftButtonDown event in the silvelright application. Since i have to talk to the WS and display the data on the page, i will have to postback my page. Correct?
04-03-2009 4:38 PM |
If the user is going to edit the data then you could just send it back to the server using a web service, I don't see any need for a postback.