Script callback returning ViewState?

Discussion in 'ASP .Net' started by Flinky Wisty Pomm, Dec 1, 2005.

  1. Okay, I'm pretty baffled by this one.

    I've got a page in a popup which takes a postcode; looks up a list of
    addresses for that postcode; then uses a callback to get the details
    for a specific address, build a JS object and pass it back to the
    window.opener.

    This used to work, but without any obvious cause it has started
    throwing an error. The error text comprises the XML returned from the
    server AND (mysteriously) the viewstate. Here's the callback method:

    <code>

    public string GetCallbackResult()
    {
    return LoadSingleAddressAsXml(_callbackArg);
    }

    private string LoadSingleAddressAsXml(string addressId)
    {
    Connection accountDetails = GetAccountDetails();
    PostcodeAnywhereProvider data = new
    PostcodeAnywhereProvider(accountDetails);
    FullAddress address = data.getAddress(addressId);

    StringWriter Output = new StringWriter(new StringBuilder());
    XmlSerializer s = new XmlSerializer( typeof( FullAddress ) );
    s.Serialize(Output,address);

    Trace.Warn(Output.ToString());

    return outstring;
    }

    </code>

    The trace shows a perfectly correct response without any additional
    text.

    The JS looks like this

    <code>
    addInitFunc(initCallback);

    function initCallback()
    {
    pageUrl='/PostcodePopup.aspx';
    _InitWebCallback();
    }
    function doCallback()
    {
    var list = getSingleElement("selAddress", "select");
    var aId = list.options[list.selectedIndex].value;

    WebForm_DoCallback('__Page',aId,receiveCallBack,null,oncallbackerror,true);
    }

    function onCallbackError(e)
    {
    alert("Oops! An error occurred while contacting the server!\nPlease
    try again in a moment\n"+e);
    }

    function receiveCallBack(xml)
    {
    var oDomDoc = Sarissa.getDomDocument();
    oDomDoc.loadXML(xml);
    var oAddress = parseAddress(oDomDoc);
    sendAddress(oAddress);
    }
    </code>

    The onCallbackError function is called and my alert runs something like

    Oops! An error occurred on the server, please try again in a moment
    /wEWHQLggdzjDgLJrO+CAQLAzrGoBwLt/YqPAwLO547CDgLt/ZbPAgLO55qCDgLt/dIPAs7n1sIPAu39vs8DAs7nooIPAu39+o8BAs7nvsQEAu39xk8CzueKhAQCk6Wj9QcC7f2Cjg4Ck6WPtQcC7f3uzwECk6XL9QQC7f3qgQcCk6XXtQQC7f32wQYCk6WT9AUCzufeQwKTpf+1BQLO56oDAs7n5sMBAs7n8oMBOUBN2Lkkie4wjPMIfrnhEv/BivE=
    <Address Building="My Parent's Address" Street="My Parent's Road"
    Locality1="Deepest Darkest Derbyshire" Locality2=" Locality3=""
    town="None Worth Mention" postcode="ABC 123" county="Derbyshire"
    country-id="335" address-id="0" />
    Flinky Wisty Pomm, Dec 1, 2005
    #1
    1. Advertising

  2. Hi,

    Did you check whether XML you are getting is valid? Please post XML

    "Flinky Wisty Pomm" <> wrote in message
    news:...
    > Okay, I'm pretty baffled by this one.
    >
    > I've got a page in a popup which takes a postcode; looks up a list of
    > addresses for that postcode; then uses a callback to get the details
    > for a specific address, build a JS object and pass it back to the
    > window.opener.
    >
    > This used to work, but without any obvious cause it has started
    > throwing an error. The error text comprises the XML returned from the
    > server AND (mysteriously) the viewstate. Here's the callback method:
    >
    > <code>
    >
    > public string GetCallbackResult()
    > {
    > return LoadSingleAddressAsXml(_callbackArg);
    > }
    >
    > private string LoadSingleAddressAsXml(string addressId)
    > {
    > Connection accountDetails = GetAccountDetails();
    > PostcodeAnywhereProvider data = new
    > PostcodeAnywhereProvider(accountDetails);
    > FullAddress address = data.getAddress(addressId);
    >
    > StringWriter Output = new StringWriter(new StringBuilder());
    > XmlSerializer s = new XmlSerializer( typeof( FullAddress ) );
    > s.Serialize(Output,address);
    >
    > Trace.Warn(Output.ToString());
    >
    > return outstring;
    > }
    >
    > </code>
    >
    > The trace shows a perfectly correct response without any additional
    > text.
    >
    > The JS looks like this
    >
    > <code>
    > addInitFunc(initCallback);
    >
    > function initCallback()
    > {
    > pageUrl='/PostcodePopup.aspx';
    > _InitWebCallback();
    > }
    > function doCallback()
    > {
    > var list = getSingleElement("selAddress", "select");
    > var aId = list.options[list.selectedIndex].value;
    >
    > WebForm_DoCallback('__Page',aId,receiveCallBack,null,oncallbackerror,true);
    > }
    >
    > function onCallbackError(e)
    > {
    > alert("Oops! An error occurred while contacting the server!\nPlease
    > try again in a moment\n"+e);
    > }
    >
    > function receiveCallBack(xml)
    > {
    > var oDomDoc = Sarissa.getDomDocument();
    > oDomDoc.loadXML(xml);
    > var oAddress = parseAddress(oDomDoc);
    > sendAddress(oAddress);
    > }
    > </code>
    >
    > The onCallbackError function is called and my alert runs something like
    >
    > Oops! An error occurred on the server, please try again in a moment
    > /wEWHQLggdzjDgLJrO+CAQLAzrGoBwLt/YqPAwLO547CDgLt/ZbPAgLO55qCDgLt/dIPAs7n1sIPAu39vs8DAs7nooIPAu39+o8BAs7nvsQEAu39xk8CzueKhAQCk6Wj9QcC7f2Cjg4Ck6WPtQcC7f3uzwECk6XL9QQC7f3qgQcCk6XXtQQC7f32wQYCk6WT9AUCzufeQwKTpf+1BQLO56oDAs7n5sMBAs7n8oMBOUBN2Lkkie4wjPMIfrnhEv/BivE=
    > <Address Building="My Parent's Address" Street="My Parent's Road"
    > Locality1="Deepest Darkest Derbyshire" Locality2=" Locality3=""
    > town="None Worth Mention" postcode="ABC 123" county="Derbyshire"
    > country-id="335" address-id="0" />
    >
    Nilesh Deshpande, Dec 1, 2005
    #2
    1. Advertising

  3. It's not a problem with the XML because no validation is occurring at
    any point - the script callback just returns a string, which in this
    case happens to be an XML fragment, but I might switch to JScript
    objects at some point. The error occurs before the document is loaded
    because control passes to onCallbackError instead of receiveCallback.

    The XML is fine, and matches what I get in the alert() except that the
    alert also contains the ViewState

    Forgive the odd schema but I've not finished setting up the
    serialization.

    <code>

    <?xml version="1.0" encoding="utf-16"?>
    <Address xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" Building="3 Dale Avenue"
    Street="Dale Avenue" Locality1="Long Eaton" Locality2="" Locality3=""
    town="Nottingham" postcode="NG10 1NP" county="Derbyshire"
    country-id="335" address-id="0">
    <CountyId>0</CountyId>
    <Country>United Kingdom</Country>
    <CountryCode>uk</CountryCode>
    <AddressStartDate>0001-01-01T00:00:00</AddressStartDate>
    <AddressEndDate>0001-01-01T00:00:00</AddressEndDate>
    <IsPrimaryAddress>false</IsPrimaryAddress>
    </Address>

    </code>
    Flinky Wisty Pomm, Dec 2, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ben Rush
    Replies:
    2
    Views:
    505
    Ben Rush
    Dec 5, 2003
  2. Steph
    Replies:
    2
    Views:
    1,645
    heislord5
    May 11, 2011
  3. ujjc001
    Replies:
    0
    Views:
    1,360
    ujjc001
    Jul 27, 2005
  4. Replies:
    11
    Views:
    650
    Christos Georgiou
    May 2, 2006
  5. sck10
    Replies:
    6
    Views:
    900
    sck10
    Sep 1, 2006
Loading...

Share This Page