views:

614

answers:

1

Hi Folks

I encouter some postback issue when using GetPostBackEventReference. Here is the Scenario:

I have a javascript modal popup dialog and got a button in this modal dialog which used to select things (this is NOT an asp:button control)

When this javascript dialog HTML button is clicked, it will call the MS AJAX web service call by the javascript: eval() method. And this MS AJAX web service call is dynamically generated. So the code is like this:

var serviceCall = svcCall + "(" + parameters + ")";   //dynamically generate the MS AJAX web service call here
eval(serviceCall);    

                                              //use eval to trigger the MS AJAX web service call

As you may all know, after complete the MS AJAX web service, you can define a callback function to handle the completion:

function OnComplete(result, userContext, methodName) {

    //force to call postback manually
    eval($(userContext[0]).val());

    //close the javascript dialog here
}

As I have mentioned before, the MS AJAX web service call is built dynamically, and when the MS AJAX web service call is construct, it will be passing a userContext which contain the postback value (i.e. "__doPostBack('ctl00$ContentPlaceHolder1$btnSelectUser','')", so when the javascript eval() is called, it simulate a asp:button click postback.

The userContext[0] basically holding a asp:hidden field's ClientID, and the hidden field's value is set during the Page_Load event:

protected void Page_Load(object sender, EventArgs e)
{
        btnSelectUser.ValidationGroup = "popupSelect";
        btnSelectUser.CausesValidation = false;
        this.hdnBtnPostback.Value = Page.ClientScript.GetPostBackEventReference(btnSelectUser, string.Empty, false);
}

As you can see, this is how I bound the asp:button (i.e. btnSelectUser) 's Click Event to the asp:hiddenfield using the GetPostBackEventReference, and set the registerForEventValidation argument to false. I have also tried to use different ValidationGroup and set the CausesValidation to false, but no hope. :(

In summarize, I bound the asp:button's Click PostBackEventReference(i.e. __doPostback(....)) to the asp:hidden field's Value attribute, and using javascript eval() to eval this hidden field's value in order to manually trigger postback.

p.s. the btnSelectUser is an asp:button control and used to call out the javascript modal dialog.

Ok, here is the Problem:

In the same page, there is some asp:validator, e.g. and , and of coz, when the page run into error, this validator and callout will display to the user. e.g. When the user didn't fill in anything and submit the form, the ValidatorCalloutExtender will display a ballon and tell the user. Imagine one of this ballon/validatorCalloutExtender come out and on top of your screen at the moment.

Then you click the btnSelectUser (asp:button) to show the javascript modal dialog, and in the dialog, you Add some users, and once you hit the SELECT button inside this modal dialog, a MS AJAX web service is trigger as mentioned above, and once this web service is complete, it eval() the asp:hidden field's value (i.e. __doPostback(...))......and do the postback manually.

However, because of the validatorCalloutExtender ballon has display, it somehow cannot trigger the postback in this way, but when I close the ballon/validatorCalloutExtender, the manual postback using eval() is just working fine. Even more strange is that, when the ballon is displayed, the first time I click the SELECT button inside this modal dialog it doesn't fire the postback, however, if I do the same thing again (i.e. open up the javascript dialog, and choose some users, then click the SELECT button again). It able to do the manual postback....and I don't understand why the first time doesn't work.

This has really drive me crazy, hope anyone here can help, would be really appreciate. Thank you so much folks. :)

Have a nice day. Looking to heard from you all shortly.

+1  A: 

When you call __doPostBack(eventTarget, eventArgument) a form submission is triggered:

This from post will proceed if WebForm_OnSubmit(); return true.

WebForm_OnSubmit result depends on ValidatorOnSubmit result, which in turn depends on

ValidatorCommonOnSubmit result if Page_ValidationActive == true.

Now if you are still with me, as in the function below:

function ValidatorCommonOnSubmit() {
    Page_InvalidControlToBeFocused = null;
    var result = !Page_BlockSubmit;
    if ((typeof(window.event) != "undefined") && (window.event != null)) {
        window.event.returnValue = result;
    }
    Page_BlockSubmit = false;
    return result;
}

The result of ValidatorCommonOnSubmit depends on Page_BlockSubmit, so the only thing to block your postback is Page_BlockSubmit == true, it has nothing to do with validation callouts.

I was unable to simulate your case, but if you could post a full code sample it will help me track down the issue.

MK