views:

134

answers:

2

I am creating one of my first Asp.Net tools and I ran in to a small bump.

Currently I am doing a postback on a buttonclick which does some server-side calculations. The server-side code then uses those calculations to alter the contents of a div. In IE and Firefox when a postback happens, the div updates as expected.

However, in chrome all postbacks do a complete refresh of the entire page. What is causing this and is there a way around this behavior?

Update: ClientSide I have the following..

    <asp:Button ID="Button2" Style="float: right" runat="server" 
OnClick="S_ButtonClick" Text="Calculate" />

Which calls a method summarized as so.

protected void S_ButtonClick(object sender, EventArgs e) 
    {
        //Code parsing values from textboxes ect.

        //Do Some Calculations

        //Output Results
        outputDiv.InnerHtml = "<h2>Foo</h2><br/>";
        outputDiv.InnerHtml += "Bar: " + calcValue;

    }

It is possible that when this postback(if I understand this correctly) happens, that it is still fully reloading in firefox and ie, but it doesn't show it. This effectively masks the postback. However, when I test in chrome, any postback completely blanks the page before reloading the state. Hopefully this clears up exactly what I am asking. Also, my C#/.Net usage might be slightly flawed and I am willing to take comments on such.

+1  A: 

As I understand it, ASP.NET AJAX partial postbacks are only support on browsers ASP.NET can detect. The last I heard (a while ago) that was ie, firefox and Safari, not Chrome. In that case it resorts to full postbacks.

To implement page updates I'd really recommend you switch to jQuery or another widely supported AJAX toolkit. (jQuery is support by Microsoft if that's an issue) There's a little bit more plumbing involved, but not much.

Doobi
So would this allow me to perform the necessary state update and server-side code execution when something like a checkbox is clicked, all without performing a postback?
maleki
Correct. From javascript you can call a page on the server using the "$.ajax" function. The page will execute on the server and you can take the response (html or otherwise) and append it to a div or whatever on your page. http://docs.jquery.com/Tutorials
Doobi
I posted my solution as an answer but I will accept yours because it seems more appropriate.
maleki
A: 

I found a solution in the form of using the built in Ajax controls. I used an UpdatePanel and ScriptManager to perform the Request. As far as I can tell, the UpdatePanel masks the postback by converting the call in to an Ajax Request and then updating a specific portion of the page.

maleki