Page view counter
Send postback cause empty page
Last post 10-26-2008 4:06 PM by ksa29. 9 replies.
Sort Posts:
04-29-2008 9:00 AM
Send postback cause empty page

Hi all,

i'm doing an silverlight application that send a request to a page via postback, it seems to execute without error (i get a correct response stream), but all my controls disapear.

What should I do ?

 

my code looks like this :

private void Add_Button_Click(object sender, RoutedEventArgs e)
{
    try
    {
        HttpWebRequest request = WebRequest.Create(new Uri("http://mysite/page.php")) as HttpWebRequest;
        request.Method = "POST";
        request.ContentType = "application/x-www-form-urlencoded";
        IAsyncResult asyncResult = request.BeginGetRequestStream(new AsyncCallback(RequestCallback), request);
    }
    catch (Exception ex)
    {
        HtmlPage.Window.Alert(ex.Message);
    }
}

private void RequestCallback(IAsyncResult ar)
{
    HttpWebRequest request = ar.AsyncState as HttpWebRequest;

    string postData = string.Format("data={0}", myTxt.Text);

    Stream requestStream = request.EndGetRequestStream(ar);
    StreamWriter streamWriter = new StreamWriter(requestStream);
    streamWriter.Write(postData);
    streamWriter.Close();

    request.BeginGetResponse(new AsyncCallback(ResponseCallback), request);
}

private void ResponseCallback(IAsyncResult ar)
{
    HttpWebRequest request = ar.AsyncState as HttpWebRequest;
    WebResponse response = request.EndGetResponse(ar);
    StreamReader sr = new StreamReader(response.GetResponseStream());
    string result = sr.ReadToEnd(); // HERE, result is OK
    sr.Close();
}

 

Why is my silverlight app empty  ?

Thanks for any advice 

 

timor.super2

Loading...
Joined on 04-14-2008
Posts 51
04-29-2008 9:59 AM
Re: Send postback cause empty page

timor.super2:
i'm doing an silverlight application that send a request to a page via postback
 

There is no postback in Silverlight. If you click the button, you won't get the postback that we used to get in ASP.NET. 

Could you please put try-catch in your code and see whether you got any error or not?  

(If this has answered your question, please click on "Mark as Answer" on this post. Thank you!)

Best Regards,
Michael Sync

Blog : http://michaelsync.net
Feed : http://michaelsync.net/feed

mchlSync

Loading...
Joined on 09-16-2005
Singapore
Posts 2,335
04-29-2008 10:23 AM
Re: Send postback cause empty page

I'm not talking about postback,

if you look at my code, you'll see that i'm sending a request to a different page, with data send via the POST method 

in the button click, i've :

        HttpWebRequest request = WebRequest.Create(new Uri("http://mysite/page.php")) as HttpWebRequest;
        request.Method = "POST";
        request.ContentType = "application/x-www-form-urlencoded";
        IAsyncResult asyncResult = request.BeginGetRequestStream(new AsyncCallback(RequestCallback), request);

 

as you can see, i've put try catch too ...

I've add try catch everywhere, but still the same error 

timor.super2

Loading...
Joined on 04-14-2008
Posts 51
04-29-2008 10:32 AM
Marked as Answer
Re: Send postback cause empty page

Do you have cross-domain issue? I mean, page.php is under different domain?  

(If this has answered your question, please click on "Mark as Answer" on this post. Thank you!)

Best Regards,
Michael Sync

Blog : http://michaelsync.net
Feed : http://michaelsync.net/feed

mchlSync

Loading...
Joined on 09-16-2005
Singapore
Posts 2,335
04-29-2008 11:02 AM
Re: Send postback cause empty page

the page won't be on another server at the end, but during the development, the page is on another server, because i'm on a localhost.

If i upload the xap on the same server it's ok Yes, because i've put a crossdomain.xml file on the server.

But, on my localhost, i've done the same thing, but i've the empty page.

So, in fact, there's no problem for the future

Can I do something for the development phasis ?

timor.super2

Loading...
Joined on 04-14-2008
Posts 51
04-29-2008 11:21 AM
Marked as Answer
Re: Send postback cause empty page

timor.super2:
Can I do something for the development phasis ?
 

You have to put crossdomain.xml in root folder "wwwroot"

 

Let's say you have three projects.

  • One project is the Silverlight project that is gonna invoke the service or page or something.    (e.g. SLTests1)
  • The other one is the ASP.NET project that is hosted Silverlight content.   (e.g. WebApplication1 )
  • Another one is the PHP or ASP.NET project that is gonna receive the POST request from Silverlight.

SLTests1
--- Page.xaml
----App.xaml

WebApplication1
---- [ClientBin]
--------------SLTests1.xap
----SLTests1TestPage.aspx

့့့h့ttp://localhost   ( NOT http://localhost/yourservice/)
----- clientaccesspolicy.xml
----- crossdomain.xml

I have tried to test with VS Development web server but not working because we can't put our crossdomain under http://localhost:50782/. Whenever we run the project, those xml files will go under "http://localhost:50782/SilverlightApplication5_Web/".

If you want to do POST request, create the Virtual Directory in IIS. then, you can put those XML files under wwwroot.

 

(If this has answered your question, please click on "Mark as Answer" on this post. Thank you!)

Best Regards,
Michael Sync

Blog : http://michaelsync.net
Feed : http://michaelsync.net/feed

mchlSync

Loading...
Joined on 09-16-2005
Singapore
Posts 2,335
04-29-2008 12:14 PM
Re: Send postback cause empty page

Thanks for your help,

I was using VS Development web server , that's why crossdomain wasn't accesible :(

Is this the reason why I can't use the debbugger too ?

timor.super2

Loading...
Joined on 04-14-2008
Posts 51
04-29-2008 12:26 PM
Marked as Answer
Re: Send postback cause empty page

timor.super2:
Is this the reason why I can't use the debbugger too ?
 

There are a Silverlight checkedbox in the properties of ASP.NET project. You have to check to enable debugging.

Which edition of VS 2008 are you using? If you are using standard editor, you won't be able to do that. This is a known issue. We already report about that to Microsoft. The workaround is that you can remove/re-add the "silverlight link" in ASP.NET then debugging should be enabled.

(If this has answered your question, please click on "Mark as Answer" on this post. Thank you!)

Best Regards,
Michael Sync

Blog : http://michaelsync.net
Feed : http://michaelsync.net/feed

mchlSync

Loading...
Joined on 09-16-2005
Singapore
Posts 2,335
04-30-2008 2:28 AM
Re: Send postback cause empty page

Oh yes ! The checkedbox !

Everything is allright now

Thank you very much 

timor.super2

Loading...
Joined on 04-14-2008
Posts 51
10-26-2008 4:06 PM
Re: Re: Send postback cause empty page

Я делаю так.Big Smile

private void Subm_Click(object sender, RoutedEventArgs e)

{

System.Windows.Browser.
HtmlDocument htmlDocument = System.Windows.Browser.HtmlPage.Document;

htmlDocument.Submit();

}

ksa29

Loading...
Joined on 10-26-2008
Posts 1
Microsoft Communities