Note that there are some explanatory texts on larger screens.

plurals
  1. POClient-Side validation prvent Manually Postback by JavaScript eval()
    primarykey
    data
    text
    <p>I encouter some postback issue when using <strong>GetPostBackEventReference</strong>. Here is the <strong>Scenario</strong>:</p> <p>I have a javascript modal popup dialog and got a button in this modal dialog which used to select things (this is <strong>NOT</strong> an asp:button control)</p> <p>When this javascript dialog HTML button is clicked, it will call the MS AJAX web service call by the <strong>javascript: eval()</strong> method. And this MS AJAX web service call is dynamically generated. So the code is like this:</p> <pre><code>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 </code></pre> <p>As you may all know, after complete the MS AJAX web service, you can define a callback function to handle the completion:</p> <pre><code>function OnComplete(result, userContext, methodName) { //force to call postback manually eval($(userContext[0]).val()); //close the javascript dialog here } </code></pre> <p>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. "<strong>__doPostBack('ctl00$ContentPlaceHolder1$btnSelectUser','')</strong>", so when the javascript <strong>eval()</strong> is called, it simulate a asp:button click postback.</p> <p>The userContext[0] basically holding a asp:hidden field's ClientID, and the hidden field's value is set during the Page_Load event:</p> <pre><code>protected void Page_Load(object sender, EventArgs e) { btnSelectUser.ValidationGroup = "popupSelect"; btnSelectUser.CausesValidation = false; this.hdnBtnPostback.Value = Page.ClientScript.GetPostBackEventReference(btnSelectUser, string.Empty, false); } </code></pre> <p>As you can see, this is how I bound the asp:button (i.e. btnSelectUser) 's Click Event to the asp:hiddenfield using the <strong>GetPostBackEventReference</strong>, and set the <strong>registerForEventValidation</strong> argument to false. I have also tried to use different <strong>ValidationGroup</strong> and set the <strong>CausesValidation</strong> to <strong>false</strong>, but no hope. :(</p> <p>In summarize, I bound the asp:button's Click <strong>PostBackEventReference</strong>(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> <p>p.s. the btnSelectUser is an asp:button control and used to call out the javascript modal dialog.</p> <p>Ok, here is the Problem:</p> <p>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.</p> <p>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.</p> <p>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.</p> <p>This has really drive me crazy, hope anyone here can help, would be really appreciate. Thank you so much folks. :)</p> <p>Have a nice day. Looking to heard from you all shortly.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload