Radwindow wont open after code is processed on RadMultiPage

3 posts, 0 answers
  1. newguy
    newguy avatar
    26 posts
    Member since:
    May 2013

    Posted 14 Aug 2013 Link to this post

    Hi Guys,

    Im busy creating a betting application using C# asp.net.
    Pretty much what happens is, at betting sites cashiers will log onto the website and may generate a voucher which is printed and given to customers.

    I am using a masterPage, the RadScriptManager and AjaxManager are found on the master page.
    My Sales.aspx page which has a RadAjaxPanel which holds a RadMultiPage control that has 2 tabs (scratchcards and vouchers).

    My Voucher Tab has a Button (Generate) which will randomly generate a voucher PIN and is supposed to open a rad window after all the code has been executed which it fails to do.

    Just as a Test i dropped a button on the page (Outside of the Panel) and was able to successfully open the rad window with that button, but the RadWindow does not open if i try open it from the Generate Button held inside of the MultiPageView Control.

    Any Ideas Why?

    aspx code for my Panel
    <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" BorderColor="Gray">
                <telerik:RadTabStrip runat="server" ID="RadTabStrip1" SelectedIndex="0"
                    MultiPageID="RadMultiPage1" CssClass="HeaderClass" Skin="Glow" 
                    BackColor="#DDDDDD" >
     
                    <Tabs>
                        <telerik:RadTab Text="Scratchcards" SelectedIndex="0">
                        </telerik:RadTab>
                        <telerik:RadTab Text="Vouchers" >
                        </telerik:RadTab>
                    </Tabs>
                </telerik:RadTabStrip>
     
                <telerik:RadMultiPage runat="server" ID="RadMultiPage1" SelectedIndex="0" Width="400px" CssClass="multiPage" >
                    <telerik:RadPageView runat="server" ID="RadPageView1" >
                        <div class="CenterDiv">
                            <table style="width:400px;margin-left:25px;">
                                <tr>
                                    <td>
                                        <asp:Label ID="Account" runat="server" ForeColor="#444444" Text="Product"></asp:Label>
                                    </td>
                                    <td>
                                        <telerik:RadComboBox ID="cboProducts" runat="server" Width="100%"></telerik:RadComboBox>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <asp:Label ID="lblSerial" runat="server" ForeColor="#444444" Text="Serial Number"></asp:Label>
                                    </td>
                                    <td>
                                        <telerik:RadMaskedTextBox ID="tbSerial" runat="server"
                                            AutoCompleteType="Disabled" CssClass="txtBox" DisplayPromptChar=" "
                                            Mask="#########" MaxLength="9" oncopy="return false" oncut="return false"
                                            onpaste="return false" PromptChar=" ">
                                        </telerik:RadMaskedTextBox>
                                    </td>
                                </tr>
                            </table>
                            <br />
                            <table style="width:400px;margin-left:25px;">
                                <tr>
                                    <td colspan="3">
                                        <asp:Label ID="lblInfo" runat="server" Font-Bold="true" Font-Size="14px" Text=""></asp:Label>
                                        <br />
                                    </td>
                                </tr>
                            </table>
     
                            <div class="scratchcardSave">
                                <br />
                                <asp:Button ID="btnCheck" runat="server" onclick="btnCheck_Click"
                                    Text="Activate" />
                                <asp:Button ID="btnClear" runat="server" onclick="btnClear_Click"
                                    Text="Clear" />
                                <asp:Button ID="btnNewScratchcard" runat="server"
                                    onclick="btnNewScratchcard_Click" Text="Sell Another" />
                            </div>
                        </div>
                </telerik:RadPageView>
                 
     
                <telerik:RadPageView runat="server" ID="RadPageView2" >
                    <div class="CenterDiv">
                        <table style="width:400px;margin-left:25px;">
                            <tr>
                                <td>
                                    <asp:Label ID="Label1" runat="server" ForeColor="#444444" Text="Product"></asp:Label>
                                </td>
                                <td>
                                    <telerik:RadComboBox ID="cboProductType" runat="server" Width="100%"></telerik:RadComboBox>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <asp:Label ID="lblVoucherAmount" runat="server" ForeColor="#444444" Text="Amount"></asp:Label>
                                </td>
                                <td>
                                    <telerik:RadMaskedTextBox ID="tbGeneratePIN" runat="server"
                                        AutoCompleteType="Disabled" CssClass="txtBox" DisplayPromptChar=" "
                                        Mask="#########" MaxLength="9" oncopy="return false" oncut="return false"
                                        onpaste="return false" PromptChar=" ">
                                                </telerik:RadMaskedTextBox>
                                </td>
                            </tr>
                        </table>
                        <br />
                         
                        <table style="width:400px;margin-left:25px;">
                            <tr>
                                <td colspan="3">
                                    <asp:Label ID="lblVoucherPIN" runat="server" Font-Bold="True" Font-Size="14px"></asp:Label>
                                    <br />
                                </td>
                            </tr>
                        </table>
     
                        <div class="scratchcardSave">
                            <br />
                            <asp:Button ID="btnVoucherGenerate" runat="server" onclick="btnVoucherGenerate_Click" Text="Generate" />
                            <asp:Button ID="btnVoucherClear" runat="server" onclick="btnVoucherClear_Click" Text="Clear" />
                        </div>
                    </div>
                </telerik:RadPageView>
            </telerik:RadMultiPage>
     
            </telerik:RadAjaxPanel>



    C# code for the Generate Button inside the PageView control

    protected void btnVoucherGenerate_Click(object sender, EventArgs e)
            {
                if (tbGeneratePIN.Text == string.Empty)
                {
                    lblVoucherPIN.ForeColor = System.Drawing.Color.Red;
                    lblVoucherPIN.Text = "Please insert voucher amount";
                }
                else
                {
                    iThNkContext.Prepaid pre = new iThNkContext.Prepaid();
     
                    String newID = "";
                    newID = Guid.NewGuid().ToString().Replace("-", "");
                    newID = newID.Substring(newID.Length - 16);
                    newID = newID.ToUpper();
     
                    // Add PIN to Prepaid DB
                    var userInfo = (from c in db.Currencies
                                    from a in db.Accounts
                                    from s in db.Sites
                                    from u in db.Users
                                    where c.CurrencyID == a.CurrencyID &&
                                            a.AccountID == u.AccountID &&
                                            s.SiteID == u.SiteID &&
                                            u.UserID == LoggedUserID)
                                    select new
                                    {
                                        AccountID = a.AccountID,
                                        CurrencyID = c.CurrencyID,
                                        CurrencySymbol = c.CurrencySymbol,
                                        SiteName = s.SiteName,
                                        AccountName = a.AccountName
                                    }).FirstOrDefault();
     
                    if (userInfo != null)
                    {
                        AccountID = userInfo.AccountID;
                        CurrencyID = userInfo.CurrencyID;
                        CurrencySymbol = userInfo.CurrencySymbol;
                    }
     
                    try
                    {
                        pre.CurrencyID = CurrencyID;
                        pre.AccountID = AccountID;
                        pre.Amount = Convert.ToDecimal(tbGeneratePIN.Text);
                        pre.SerialNumber = ("_");
                        pre.Pin = newID;
                        pre.TransactionTypeID = 2;
                        pre.SalesUserID = LoggedUserID);
                        pre.SalesDate = DateTime.Now;
                        pre.IsActivated = true;
                        pre.IsActive = true;
     
                        db.Prepaids.InsertOnSubmit(pre);
                        db.SubmitChanges();
     
                        pre.SerialNumber = Convert.ToString(pre.PrepaidID).PadLeft(9, '0');
                        db.SubmitChanges();
     
                        Amount = pre.Amount;
                        SerialNumber = pre.SerialNumber;
                        PinNumber = pre.Pin;
                        SiteName = userInfo.SiteName;
                        accountID = userInfo.AccountID;
                        AccountName = userInfo.AccountName;
     
                        // update the database and set isPrinted = 1
                        pre.IsPrinted = true;
                        db.SubmitChanges();
                        tbGeneratePIN.Text = string.Empty;
     
                        RadWindow newWindow = new RadWindow();
                        newWindow.NavigateUrl = "Vouchers.aspx";
                        newWindow.Top = Unit.Pixel(22);
                        newWindow.VisibleOnPageLoad = true;
                        newWindow.Left = Unit.Pixel(0);
                        RadWindowManager1.Windows.Add(newWindow);  
                    }
                    catch (Exception ex)
                    {
                        lblVoucherPIN.ForeColor = System.Drawing.Color.Red;
                        lblVoucherPIN.Text = ex.Message;
                    }
                }
            }

    Code i am using to open the RadWindow on the button outside of the PageView (This code works only if it is not inside of the PageView)

    protected void RadButton1_Click(object sender, EventArgs e)
        {
            RadWindow newWindow = new RadWindow();
            newWindow.NavigateUrl = "http://www.google.com";
            newWindow.Top = Unit.Pixel(22);
            newWindow.VisibleOnPageLoad = true;
            newWindow.Left = Unit.Pixel(0);
            RadWindowManager1.Windows.Add(newWindow);
        }


    Thanx in advance
  2. Marin Bratanov
    Admin
    Marin Bratanov avatar
    3595 posts

    Posted 14 Aug 2013 Link to this post

    Hello,

    I see you add a newly generated RadWindow to the Windows collection of a RadWindowManager. This manager, however, is not in the RadAjaxPanel, so it is not updated in the browser, which means that the new RadWindow is not transferred to the client.

    What I would advise:
    - use the approach from this sticky thread to open the RadWindow: http://www.telerik.com/community/forums/aspnet-ajax/window/opening-radwindow-from-the-server.aspx. You can declare it in the RadWIndowManager Windows collection in the markup. You can additionally use its Client-side API to modify it in the function that will open it. This help article will show you other ways to open a RadWindow with JavaScript if you do not want to have it in the markup: http://www.telerik.com/help/aspnet-ajax/window-programming-opening.html. You will see how the RadWIndowManager can create RadWIndows on the fly

    - if that is not a viable option for you, you can simply add the RadWindow to a placeholder inside the RadAjaxPanel. Note that, in this case, you would need to treat it like any other dynamic ASP contorl - recreating it after a postback will be needed. The RadWindowManager otherwise stores its Windows collection in the ViewState. I would still advise on opening it with a script registration, however, instead of using the VisibleOnPageLoad property.

    Regards,
    Marin Bratanov
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. newguy
    newguy avatar
    26 posts
    Member since:
    May 2013

    Posted 02 Sep 2013 Link to this post

    Hi Martin,

    thank you for the reply.

    I found another way around it, instead of using the RadWindow i used an iframe that is loaded far off the screen (left: -10000px).
    so as soon as the iFrame opens it prints the voucher and then closes the iFrame.

    sorry for the late reply.
Back to Top