This is a migrated thread and some comments may be shown as answers.

RadWindow Dialog Return stops postback of server button?

4 Answers 212 Views
Window
This is a migrated thread and some comments may be shown as answers.
justins
Top achievements
Rank 1
justins asked on 21 Jul 2008, 03:54 PM
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!

4 Answers, 1 is accepted

Sort by
0
justins
Top achievements
Rank 1
answered on 21 Jul 2008, 06:15 PM
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.
0
Georgi Tunev
Telerik team
answered on 22 Jul 2008, 10:33 AM
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
0
Thomas Kopp
Top achievements
Rank 1
answered on 17 Aug 2009, 06:28 PM
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>

 

0
Thomas Kopp
Top achievements
Rank 1
answered on 17 Aug 2009, 07:52 PM
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!
Tags
Window
Asked by
justins
Top achievements
Rank 1
Answers by
justins
Top achievements
Rank 1
Georgi Tunev
Telerik team
Thomas Kopp
Top achievements
Rank 1
Share this question
or