RadWindow Dialog Return stops postback of server button?

5 posts, 0 answers
  1. justins
    justins avatar
    11 posts
    Member since:
    Apr 2007

    Posted 21 Jul 2008 Link to this post

    I'm trying a variation of the RadWindow DialogReturnValue sample:

    I have a form with a server-side button called Button1.  Button1 is set as the OpenerElementID for the RadWindow control.  Just like the DialogReturnValue sample, I  return some text from a textbox to the calling page.

    I can successfully use the ClientCallbackFunction to return this value client-side.  However, I want to take this a step further.  I need to have the Button1 complete its server click event and use that value returned from the RadWindow for some server-side processing.  Button1 never posts back and I'm not sure how to reference the return value of the dialog in the server code.  Why is that and how do I make this work?  Thanks!
  2. justins
    justins avatar
    11 posts
    Member since:
    Apr 2007

    Posted 21 Jul 2008 Link to this post

    Here is my work-around for this so far:

    I have the ClientCallbackFunction set the dialog return value to a server-side hidden field control.  Next, I call __doPostBack within the ClientCallbackFunction like this:

    var btnName = $get("<%=Button1.ClientID%>").name; 
    __doPostBack(btnName,""); 

    This then posts back the form and calls the server-side Click event for Button1.  From there I can get the value of the server-side hidden field control where I stored my dialog return value.

    There's got to be an easier method than this.  Am I right?
    Thank you.
  3. Georgi Tunev
    Admin
    Georgi Tunev avatar
    7207 posts

    Posted 22 Jul 2008 Link to this post

    Hello justins,

    Actually this is the method that I would recommend. RadWindow acts like the browser's popup and the communication between the parent and the content page is done on the client. Once you receive the argument on the client, you need to send it somehow to the server. As an alternative you can use an Ajax callback or if you are using RadAjax - AjaxRequest. More information on the second approach is available in the Client-Side API section of RadAjax's documentation.



    Sincerely yours,
    Georgi Tunev
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  4. Thomas Kopp
    Thomas Kopp avatar
    4 posts
    Member since:
    Aug 2009

    Posted 17 Aug 2009 Link to this post

    Hi Georgi;

    This is urgent, I'm on a deadline...

    I can't get the above example to work.  It's not finding the doPostback event, apparently.  When I call it, I get the javascript error "Object expected".  The control name is being passed (not the TestIt function, which works).  I've also tried "_doPostBack" with the same result.  Examing the page source, my call within the clientClose function matches the calls generated by the server, except it's not within a set timeout call.

    Please help...

     

    <script type="text/javascript">

     

     

    function openNewWindow(windowURL) {

     

     

    var oWnd = radopen(windowURL, null);

     

    oWnd.center();

    }

     

    function clientClose(sender, args) {

     

     

    if (args.get_argument() != null) {

     

     

    var hdnFaxID = $get("<%=hdnFaxID.ClientID%>");

     

     

    var btnFaxIDName = $get("<%=btnTestFax.ClientID%>").name;

     

    hdnFaxID.value = args.get_argument();

    alert(btnFaxIDName +

    ', ' + hdnFaxID.value);

     

    testIt(btnFaxIDName, hdnFaxID.value);

    doPostBack(btnFaxIDName,

    '');

     

    }

    }

     

    function testIt(name, value) {

     

    alert(

    'Passed It: ' + name + ', ' + value);

     

    }

     

    </script>

     

  5. Thomas Kopp
    Thomas Kopp avatar
    4 posts
    Member since:
    Aug 2009

    Posted 17 Aug 2009 Link to this post

    Ok, got it.

    First, we need the button which will have the postback event attached to it.  However, we (or I, at least) don't want it to show, so we apply the css style "hidden" to it:

    .invisibleBtn

    {

     

    visibility:hidden;

     

    }


    then we have the controls:  the button, and the HiddenField to hold the value returned from the RadWindow:

     

    <

     

    asp:Button ID="btnFaxID" CssClass="invisibleBtn" CausesValidation="false" runat="server" OnClick="btnFaxID_Click" />

     

     

     

    <asp:HiddenField ID="hdnFaxID" runat="server" />

     


    Setting "CausesValidation" to false prevents required fields, etc. to be marked as invalid when the page posts back and does its thing.

    Then the javascript:

    I don't know if it's a .NET 2.0 thing or not, but "doPostBack" (or "_doPostBack") doesn't work, it throws the aforementioned "object expected" javascript error.  Upon examining the page source, I saw that what was getting called was WebForm_DoPostBackWithOptions, like here:

    <input type="submit" name="ctl00$cphMain$btnTestFax" value="Test" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ctl00$cphMain$btnTestFax&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, false, false))" id="ctl00_cphMain_btnTestFax" class="inputBtn" valign="bottom" />


    This is verbatim; the HTML-encoded quotes are directly from the source)

    The documentation (sort of) is:

        function WebForm_PostBackOptions(eventTarget, eventArgument, validation, validationGroup, actionUrl, trackFocus, clientSubmit)

    Setting the validate parameter to false didn't prevent validation controls from firing, thus the CausesValidation="false" above.

    So the clientClose function now looks like this:

     

    function clientClose(sender, args) {

     

     

    if (args.get_argument() != null) {

     

     

    var hdnFaxID = $get("<%=hdnFaxID.ClientID%>");

     

     

    var btnFaxIDName = $get("<%=btnFaxID.ClientID%>").name;

     

    hdnFaxID.value = args.get_argument();

    WebForm_DoPostBackWithOptions(

    new WebForm_PostBackOptions(btnFaxIDName, '', false, '', '', false, true));

     

    }

    }


    Notice that I set the last parameter, "clientSubmit," to true.  If you don't do this there will be no postback to the server.

    Now it posts back to the button event correctly, with the HiddenField value available server-side.  Sweet.

    Thanks!
Back to Top