Skip to main content

Microsoft Silverlight

Answered Question How to Submit or POST a ASP.NET page from a Silverlight ApplicationRSS Feed

(0)

amurawatSilver
amurawat...

Member

Member

0 points

4 Posts

How to Submit or POST a ASP.NET page from a Silverlight Application

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.

<body topmargin="0">

<form id="form1" runat="server">

<div>

<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true">

</asp:ScriptManager>

<table width="100%">

<tr style="background-color: Yellow; height: 300px">

<td>

<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">

<ContentTemplate>

<asp:Silverlight ID="Silverlight1" Source="~/ClientBin/MeshSilverlightApplication.xap"

runat="server" Height="100%" Width="100%">

</asp:Silverlight>

</ContentTemplate>

</asp:UpdatePanel>

</td>

</tr>

</table>

</div>

</form>

<form id="generateFileForm" method="post">

<div>

<table>

<tr>

<td>

<%--<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">

<ContentTemplate>--%>

<input id="Button1" type="button" value="button" onclick="BLOCKED SCRIPTSayHello();" />

<input id="Text1" type="text" />

<%-- </ContentTemplate>

</asp:UpdatePanel>--%>

</td>

</tr>

</table>

</div>

</form>

</body>

 

The code on my silverlight app from where i want to submit the second form on my page.

HtmlDocument doc = HtmlPage.Document;

doc.Submit("generateFileForm");

muthu.v
muthu.v

Member

Member

438 points

87 Posts

Re: How to Submit or POST a ASP.NET page from a Silverlight Application

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

"If this has answered your question, pls mark it as "answer""

Muthu
My blog with some silverlight articles

mepfuso
mepfuso

Member

Member

683 points

153 Posts

Re: How to Submit or POST a ASP.NET page from a Silverlight Application

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

 

 

...: Between the iron gates of fate, the seeds of time were sown :...

amurawatSilver
amurawat...

Member

Member

0 points

4 Posts

Re: Re: How to Submit or POST a ASP.NET page from a Silverlight Application

I tried the GET option as well but it did not work.

muthu.v
muthu.v

Member

Member

438 points

87 Posts

Re: Re: How to Submit or POST a ASP.NET page from a Silverlight Application

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.

"If this has answered your question, pls mark it as "answer""

Muthu
My blog with some silverlight articles

jackbond
jackbond

Contributor

Contributor

2820 points

725 Posts

Re: How to Submit or POST a ASP.NET page from a Silverlight Application

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. :)

amurawatSilver
amurawat...

Member

Member

0 points

4 Posts

Re: How to Submit or POST a ASP.NET page from a Silverlight Application

Not sure what you mean by using the WS to relay service.... Can you please give me some pointers...

.netdan
.netdan

Contributor

Contributor

3392 points

513 Posts

Re: How to Submit or POST a ASP.NET page from a Silverlight Application

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?

Remember to click "Answer" if this has helped you!

Dan Birch
MCSD, MCAD, MCP
Free Silverlight Controls | Free .NET Silverlight CMS

jackbond
jackbond

Contributor

Contributor

2820 points

725 Posts

Answered Question

Re: How to Submit or POST a ASP.NET page from a Silverlight Application

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.

amurawatSilver
amurawat...

Member

Member

0 points

4 Posts

Re: How to Submit or POST a ASP.NET page from a Silverlight Application

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?

.netdan
.netdan

Contributor

Contributor

3392 points

513 Posts

Re: How to Submit or POST a ASP.NET page from a Silverlight Application

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.

Remember to click "Answer" if this has helped you!

Dan Birch
MCSD, MCAD, MCP
Free Silverlight Controls | Free .NET Silverlight CMS
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities