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

Return value to parent window using codebehind?

3 Answers 190 Views
Window
This is a migrated thread and some comments may be shown as answers.
Laura
Top achievements
Rank 1
Laura asked on 03 Nov 2008, 05:11 AM
I have created a wizard using rad window. My parent window opens a modal window when the user clicks a button to add users to the system. The wizard has 3 pages and on the last page I have a save button. That button has an onclick event and an onclientclick event. I see that the client event occurs first. In the server click code, an order ID is generated that needs to be sent to the parent window to rebind my radgrid using that order id. If the client onclick occurs first, is there anyway to set the window arg to the order id on the server code behind? If not, is there any what that the code behind can be called after the client code?

Thanks,
Laura

3 Answers, 1 is accepted

Sort by
0
Georgi Tunev
Telerik team
answered on 05 Nov 2008, 03:12 PM
Hello Laura,

You can call the JavaScript code from the server, by outputting a JavaScript function, e.g. not to use the OnClientClick event. More information on how to call JavaScript code from the server is available in various sites in the Net. You can also check the following KB article that shows how to call radalert() in such scenario - the logic is the same:
http://www.telerik.com/support/kb/article/b454K-gtd-b454T-cec-b454c-cec.aspx


Sincerely yours,
Georgi Tunev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Laura
Top achievements
Rank 1
answered on 06 Nov 2008, 07:10 PM
Thank you Georgi. I was successful in getting this to work. Only problem now is I also have another button(back button) on the page, and that button also has both the onclientclick and onclick calls. I don't care in what order they perform, so I would like to leave it the way it is. Only problem is that since I introduced the javascript call in the c# for the save button, the back button does not execute the javascript.

So I changed this second button to also only work on the server and when the button is clicked, my page refreshes, and redraws the page, and then goes back to the previous page. Why would it redraw?  Here is my code:


 <telerik:RadScriptManager ID="RadScriptManager1" Runat="server">
    </telerik:RadScriptManager>
    
     <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">  
      <ClientEvents OnRequestStart="centerUpdatePanel();" />
                <AjaxSettings>
                    <telerik:AjaxSetting AjaxControlID="backButton">
                    </telerik:AjaxSetting>
                    <telerik:AjaxSetting AjaxControlID="SAVEBUTTON">
                    </telerik:AjaxSetting>
                </AjaxSettings>
            </telerik:RadAjaxManager>

....
  <asp:Button ID="backButton" runat="server"   OnClick="saveGrid"  
                     style="width:100px;" Text="&lt;&lt; Back" />
                &nbsp;&nbsp;&nbsp;
                <asp:Button ID="SAVEBUTTON" runat="server" CausesValidation="false"
                    OnClick="saveGridAndCreateUsers"  
                    style="width:100px;" Text="Finish &gt;&gt;" />





     
.........


public void saveGrid(Object sender, EventArgs e)
    {
        foreach (GridDataItem item in AlaCartePriceGrid.MasterTableView.Items)
        {
            System.Web.UI.WebControls.CheckBox chkbxEntitled = (System.Web.UI.WebControls.CheckBox)item["CHECKED"].FindControl("Entitled");
            System.Web.UI.WebControls.CheckBox chkbxInvoice = (System.Web.UI.WebControls.CheckBox)item["INCLINV"].FindControl("InclInv");
            RadNumericTextBox txtboxPrice = (RadNumericTextBox)item["alaPrice"].FindControl("alaPrice");


            int service_id = Convert.ToInt32(AlaCartePriceGrid.MasterTableView.DataKeyValues[item.ItemIndex]["service_id"]);
            Boolean oldIchecked = Convert.ToBoolean(AlaCartePriceGrid.MasterTableView.DataKeyValues[item.ItemIndex]["Checked"]);
            double oldPrice = Convert.ToDouble(AlaCartePriceGrid.MasterTableView.DataKeyValues[item.ItemIndex]["Price"]);
            Boolean oldIncludeInvoice = Convert.ToBoolean(AlaCartePriceGrid.MasterTableView.DataKeyValues[item.ItemIndex]["InvoiceChecked"]);


            Boolean entitled = chkbxEntitled.Checked;
            Boolean inclInvoice = chkbxInvoice.Checked;
            double price = Convert.ToDouble(txtboxPrice.Text);
            string package_cdAla = package_cd.Text + "ala";

            if (oldIchecked != entitled)
                Insert_update_checkbox(temptablename.Text, package_cdAla, service_id, 0, entitled);
            if (oldIncludeInvoice != inclInvoice)
                Insert_update_checkbox(temptablename.Text, package_cdAla, service_id, 1, inclInvoice);
            if (oldPrice != price)
                Insert_update_price(temptablename.Text, package_cdAla, service_id, price);
        }

 
        RadAjaxManager1.ResponseScripts.Add(@"Sys.Application.add_load( function goBackOneStep() {

        var oWnd = GetRadWindow();


        var odid = document.getElementById('odid');
        var productname = document.getElementById('productname');
        var SAPID = document.getElementById('SAPID');
        var oid = document.getElementById('oid');
        var productid = document.getElementById('productid');
        var temptablename = document.getElementById('temptablename');
        var package_cd = document.getElementById('package_cd');
        var licensePrice = document.getElementById('licensePrice');
        var numUsers = document.getElementById('numUsers');
        var email = document.getElementById('email');
        var packagePrice = document.getElementById('packagePrice');

        var windowURL = 'v8Wizard_2.aspx?sbODID=' + odid.value + '&sbproductid=' + productid.value + '&SAPID=' + SAPID.value +
                 '&lPrice=' + licensePrice.value + '&email=' + email.value + '&ttt=' + temptablename.value + '&p_cd=' + package_cd.value +
                  '&sbOID=' + oid.value + '&numUsers=' + numUsers.value + '&packagePrice=' + packagePrice.value;

        oWnd.setUrl(windowURL);

       })");
 
    }


    public void saveGridAndCreateUsers(Object sender, EventArgs e)
    {
        foreach (GridDataItem item in AlaCartePriceGrid.MasterTableView.Items)
        {
            System.Web.UI.WebControls.CheckBox chkbxEntitled = (System.Web.UI.WebControls.CheckBox)item["CHECKED"].FindControl("Entitled");
            System.Web.UI.WebControls.CheckBox chkbxInvoice = (System.Web.UI.WebControls.CheckBox)item["INCLINV"].FindControl("InclInv");
            RadNumericTextBox txtboxPrice = (RadNumericTextBox)item["alaPrice"].FindControl("alaPrice");


            int service_id = Convert.ToInt32(AlaCartePriceGrid.MasterTableView.DataKeyValues[item.ItemIndex]["service_id"]);
            Boolean oldIchecked = Convert.ToBoolean(AlaCartePriceGrid.MasterTableView.DataKeyValues[item.ItemIndex]["Checked"]);
            double oldPrice = Convert.ToDouble(AlaCartePriceGrid.MasterTableView.DataKeyValues[item.ItemIndex]["Price"]);
            Boolean oldIncludeInvoice = Convert.ToBoolean(AlaCartePriceGrid.MasterTableView.DataKeyValues[item.ItemIndex]["InvoiceChecked"]);


            Boolean entitled = chkbxEntitled.Checked;
            Boolean inclInvoice = chkbxInvoice.Checked;
            double price = Convert.ToDouble(txtboxPrice.Text);
            string package_cdAla = package_cd.Text + "ala";

            if (oldIchecked != entitled)
                Insert_update_checkbox(temptablename.Text, package_cdAla, service_id, 0, entitled);
            if (oldIncludeInvoice != inclInvoice)
                Insert_update_checkbox(temptablename.Text, package_cdAla, service_id, 1, inclInvoice);
            if (oldPrice != price)
                Insert_update_price(temptablename.Text, package_cdAla, service_id, price);
        }
        int nUsers = Convert.ToInt32(numUsers.Value);
        string tableName = temptablename.Text;
        string packagecd = package_cd.Text;
        string sEmail = email.Text;


        int nOrderID = Convert.ToInt32(oid.Text);
        int nProductID = Convert.ToInt32(productid.Text);
        int nOrderDetailID = Convert.ToInt32(odid.Text);
        string sSAPID = SAPID.Text;
        double dblPrice = Convert.ToDouble(packagePrice.Value);
        string pwd, name;
        for (int i = 0; i < nUsers; i++)
        {
            //generate random unique username and password and put it into the login_name and password fields

            pwd = RandomPassword.Generate(5, 5);
            name = RandomPassword.Generate(5, 5);
            name = Request.QueryString["SAPID"].ToString() + "_" + name;

            nOrderDetailID = Convert.ToInt32(odid.Text);
            int inserted = Insert_User_Calling_StoredProc(tableName, sSAPID, packagecd, name, pwd, sEmail, true, nOrderID, nOrderDetailID, nProductID, dblPrice);

        }
        saveLicensePrice();

        //Session["orderDetailID"] = nOrderDetailID;
        Session["orderDetailID"] = odid.Text;
        RadAjaxManager1.ResponseScripts.Add(@"Sys.Application.add_load( function saveAndGoBackToParent() {

            var oArg = new Object();

            var odidtxtbox = document.getElementById('odid');
            var numUserstxtbox = document.getElementById('numUsers');

            var odid = odidtxtbox.value;
            var numUsers = numUserstxtbox.value;

            oArg.odid = odid;
            oArg.numUsers = numUsers;

            var oWnd = GetRadWindow();

            oWnd.argument = oArg;
            oWnd.close();
    })");
0
Georgi Tunev
Telerik team
answered on 11 Nov 2008, 11:22 AM
Hello Laura,

I believe that the problem is that the code is added to Sys.Application.Load() but is not removed after that. Try the approach that is shown in this forum post:
http://www.telerik.com/community/forums/aspnet-ajax/window/radalert-problem-in-a-postback.aspx#666452

And if the problem still persist, please prepare a small sample project where the problem can be reproduced and send it to us in a support ticket - we will check it right away.



All the best,
Georgi Tunev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Window
Asked by
Laura
Top achievements
Rank 1
Answers by
Georgi Tunev
Telerik team
Laura
Top achievements
Rank 1
Share this question
or