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

PopUp User Control doesn't close after Insert

7 Answers 138 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Elliott
Top achievements
Rank 2
Elliott asked on 28 Jun 2010, 03:32 PM
I wrote a page that opens a pop-up user control to insert an order item from a large grid of items
the grid is Linq to SQL
I am using VS2010 / .NET 4.0

after the insert the pop-up doesn't automatically close
maybe because I'm inserting into another database?

the grid of the calling program
<%@ Page Title="" Language="VB" MasterPageFile="~/Brunswick.master" AutoEventWireup="false" CodeFile="Items.aspx.vb" Inherits="Items" %>
<asp:Content ID="cntHead" ContentPlaceHolderID="cpHead" Runat="Server">
    <title>Brunswick Online Orders - Items</title>
<link href="Brunswick.css" rel="Stylesheet" />
</asp:Content>
<asp:Content ID="cntBody" ContentPlaceHolderID="cpHolder" Runat="Server">
    <telerik:RadScriptManager ID="rsManager" runat="server" />
    <telerik:RadCodeBlock ID="rcBlock" runat="server">
        <script type="text/javascript">
        function RowDblClick(sender, eventArgs) {
            sender.get_masterTableView().editItem(eventArgs.get_itemIndexHierarchical());
        }
        function doFilter(sender,e) {
            var masterTable = $find("<%= rgItems.ClientID %>").get_masterTableView();
            masterTable.filter(sender, sender.value, Telerik.Web.UI.GridFilterFunction.StartsWith, true);
        }
        </script>
    </telerik:RadCodeBlock>
    <telerik:RadAjaxManager ID="raManager" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="rgItems">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="rgItems" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
    <table border="0" cellpadding="0" cellspacing="0">
    <tr>
    <td colspan="2" align="center">
        <asp:Label ID="lblShowName" runat="server" />
        <asp:HiddenField ID="hdnDivisionID" runat="server" />
    </td>
    <td colspan="2" align="center">
        <asp:Button ID="btnReturn" Text="Return To Order" runat="server" />
    </td>
    </tr>
    <tr>
    <td>Dealer Number</td>
    <td>
        <asp:Label ID="lblDealerNumber" runat="server" />
    </td>
    <td>Dealer Name</td>
    <td>
        <asp:Label ID="lblDealerName" runat="server" />
        <asp:HiddenField ID="hdnOrderID" runat="server" />
    </td>
    </tr>
    <tr>
    <td colspan="4">
    <telerik:RadGrid ID="rgItems" AutoGenerateColumns="False" AllowPaging="True"
            runat="server" AllowFilteringByColumn="True" AllowSorting="True" GridLines="None">
        <GroupingSettings CaseSensitive="false" />
        <ClientSettings>
            <Scrolling AllowScroll="True" UseStaticHeaders="True"/>
        </ClientSettings>
        <MasterTableView DataKeyNames="ItemID" EditMode="PopUp">
        <Columns>
            <telerik:GridBoundColumn UniqueName="ItemID" DataField="ItemID" Visible="False">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn UniqueName="LNSPartNo" DataField="LNSPartNo" HeaderText="LNS Part No" HeaderStyle-Width="80px">
            </telerik:GridBoundColumn>
more columns here
            <telerik:GridBoundColumn UniqueName="ShowTenTerms" DataField="ShowTenTerms" HeaderText="Show Dat Terms" HeaderStyle-Width="60px" DataFormatString="{0:$###,###.##}" ShowFilterIcon="false">
            </telerik:GridBoundColumn>
        </Columns>
        <EditFormSettings UserControlName="OrderItem.ascx" EditFormType="WebUserControl">
        </EditFormSettings>
        </MasterTableView>
            <ClientSettings>
                <ClientEvents OnRowDblClick="RowDblClick" />
            </ClientSettings>
    </telerik:RadGrid>
    </td>
    </tr>
    </table>
</asp:Content>
and it's code behind
Imports Telerik.Web.UI
Imports System.Data

Partial Class Items
    Inherits System.Web.UI.Page

    Enum CostSource As Integer
        SpringDatingInvPrice = 1
        SpringDatingNetTerms = 2
        ShowOnlyInvPrice = 3
        ShowOnlyNetTerms = 4
        UserSpecified = 5
        Unspecified_Unknown = 6
    End Enum

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim OrderID, DivisionID As Integer
        Dim ws As CommonFunctions
        If Page.IsPostBack Then
        Else
            SaveQueryStringVariables()
            OrderID = CInt(hdnOrderID.Value)
            DivisionID = CInt(hdnDivisionID.Value)
            ws = New CommonFunctions
            rgItems.DataSource = ws.GetItems(DivisionID)
            rgItems.DataBind()
        End If
        ws = Nothing
    End Sub

    Private Sub SaveQueryStringVariables()
        Dim OrderID, DivisionID As Integer
        Dim ds As DataSet = Nothing
        Dim dr As DataRow = Nothing
        Dim ShowAbbreviation, ShowName, DealerName As String
        Dim DealerNumber As Int64 = 0
        Dim sb As StringBuilder = Nothing
        Dim ws As CommonFunctions

        ws = New CommonFunctions
        If Request.QueryString("OrderID") Is Nothing Then
            Exit Sub
        End If
        OrderID = Request.QueryString("OrderID")
        hdnOrderID.Value = OrderID
        ds = ws.GetOrderInformation(OrderID)
        If ds.Tables.Count < 1 Then
        ElseIf ds.Tables(0).Rows.Count > 0 Then
            dr = ds.Tables(0).Rows(0)
        End If
        DivisionID = CInt(dr("DivisionID"))
        hdnDivisionID.Value = DivisionID
        ShowAbbreviation = CStr(dr("ShowAbbreviation"))
        sb = New StringBuilder(ShowAbbreviation)
        sb.Append(" - ")
        sb.Append(CStr(dr("ShowName")))
        ShowName = sb.ToString
        lblShowName.Text = ShowName
        DealerNumber = CType(dr("DealerNumber"), Int64)
        lblDealerNumber.Text = CStr(DealerNumber)
        DealerName = CStr(dr("DealerName"))
        lblDealerName.Text = DealerName
    End Sub

    Protected Sub rgItems_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles rgItems.ItemDataBound
        Dim OrderControl As UserControl = Nothing
        Dim hDivisionID, hDealerNumber As HiddenField
        If TypeOf e.Item Is GridEditFormItem _
            AndAlso e.Item.IsInEditMode Then
            OrderControl = CType(e.Item.FindControl(GridEditFormItem.EditFormUserControlID), UserControl)
            hDivisionID = DirectCast(OrderControl.FindControl("hdnDivisionID"), HiddenField)
            hDivisionID.Value = hdnDivisionID.Value
            hDealerNumber = DirectCast(OrderControl.FindControl("HdnDealerNumber"), HiddenField)
            hDealerNumber.Value = lblDealerNumber.Text
        End If
    End Sub

    Protected Sub rgItems_NeedDataSource(ByVal source As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles rgItems.NeedDataSource
        Dim DivisionID As Integer
        Dim ws As New CommonFunctions
        DivisionID = CInt(hdnDivisionID.Value)
        rgItems.DataSource = ws.GetItems(DivisionID)
        ws = Nothing
    End Sub

    Protected Sub btnReturn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnReturn.Click
        Dim OrderID As Integer
        Dim sb As StringBuilder = Nothing
        OrderID = CInt(hdnOrderID.Value)
        sb = New StringBuilder("OrderItems.aspx")
        sb.Append("?OrderID=")
        sb.Append(OrderID.ToString)
        Response.Redirect(sb.ToString)
    End Sub
End Class

the user control
<%@ Control Language="VB" AutoEventWireup="false" CodeFile="OrderItem.ascx.vb" Inherits="OrderItem" %>
<table border="1" cellpadding="1" cellspacing="1" style="background-color:#FFCC99;">
<tr>
<td>
    <asp:HiddenField ID="hdnDivisionID" runat="server" />
</td>
<td>
    <asp:HiddenField ID="hdnDealerNumber" runat="server" />
</td>
</tr>
<tr>
<td>ItemID</td>
<td>
    <asp:Label ID="lblItemID" Text='<%# DataBinder.Eval( Container, "DataItem.ItemID") %>' runat="server" />
</td>
</tr>
<tr>
<td>LNS Part Number</td>
<td>
    <asp:Label ID="lblLNSPartNo" Text='<%# DataBinder.Eval( Container, "DataItem.LNSPartNo") %>' runat="server" />
</td>
</tr>
<tr>
<td>KMS Part Number</td>
<td>
    <asp:Label ID="lblKMSPartNo" Text='<%# DataBinder.Eval( Container, "DataItem.KMSPartNo") %>' runat="server" />
</td>
</tr>
<tr>
<td>Description</td>
<td>
    <asp:Label ID="lblDescription" Text='<%# DataBinder.Eval(Container, "DataItem.Description") %>' runat="server" />
</td>
</tr>
<tr>
<td>Net Cost</td>
<td>
    <telerik:RadNumericTextBox ID="rntbNetCost" runat="server">
    </telerik:RadNumericTextBox>
</td>
</tr>
<tr>
<td>Cost Source</td>
<td>
    <asp:Label ID="lblCostSource" runat="server" />
    <asp:HiddenField ID="hdnCostSource" runat="server" />
    <asp:HiddenField ID="hdnNetCost" runat="server" />
</td>
</tr>
<tr>
<td>Quantity</td>
<td>
    <telerik:RadNumericTextBox ID="rntbQuantity" DataType="System.Integer" NumberFormat-DecimalDigits="0" runat="server">
    </telerik:RadNumericTextBox>
    <asp:RequiredFieldValidator ID="rfvQuantity" ControlToValidate="rntbQuantity" ErrorMessage="Quantity Required" runat="server" />
</td>
</tr>
<tr>
<td>
    <asp:Button ID="btnAddtoOrder" Text="Add to Order" CommandName="AddtoOrder" runat="server" />
</td>
<td align="right">
    <asp:Button ID="btnCancel" Text="Cancel" CommandName="Cancel" CausesValidation="false" runat="server" />
</td>
</tr>
</table>
and its code behind
Imports System.Data

Partial Class OrderItem
    Inherits System.Web.UI.UserControl

    Private _dataItem As Object
    Public Property DataItem() As Object
        Get
            Return Me._dataItem
        End Get
        Set(ByVal value As Object)
            Me._dataItem = value
        End Set
    End Property

    Protected Sub Page_DataBinding(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.DataBinding
        Dim dItem As Object = DataItem
        Dim SpringInvPrice, SpringTenTerms, ShowInvPrice, ShowTenTerms, NetCost As Double

        SpringInvPrice = CType(DataBinder.Eval(DataItem, "SpringInvPrice"), Double)
        SpringTenTerms = CType(DataBinder.Eval(DataItem, "SpringTenTerms"), Double)
        ShowInvPrice = CType(DataBinder.Eval(DataItem, "ShowInvPrice"), Double)
        ShowTenTerms = CType(DataBinder.Eval(DataItem, "ShowTenTerms"), Double)
        If ShowTenTerms > 0 Then
            NetCost = ShowTenTerms
            hdnCostSource.Value = 4
            lblCostSource.Text = "Show Only Net Terms"
        ElseIf ShowInvPrice > 0 Then
            NetCost = ShowInvPrice
            hdnCostSource.Value = 3
            lblCostSource.Text = "Show Only Net Invoice"
        ElseIf SpringTenTerms > 0 Then
            NetCost = SpringTenTerms
            hdnCostSource.Value = 2
            lblCostSource.Text = "Spring Dating Net Terms"
        ElseIf SpringTenTerms > 0 Then
            NetCost = SpringInvPrice
            hdnCostSource.Value = 1
            lblCostSource.Text = "Spring Dating Net Invoice"
        Else
            NetCost = 0
            hdnCostSource.Value = 6
            lblCostSource.Text = "Unknown/Unspecified"
        End If
        rntbNetCost.Value = NetCost
        hdnNetCost.Value = NetCost
    End Sub

    Protected Sub btnAddtoOrder_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAddtoOrder.Click
        Dim OrderID, DivisionID, ItemID, Qty, OrderItemID, CostSource As Integer
        Dim DealerNumber As Int64
        Dim LNSPartNo, KMSPartNo As String
        Dim NetCost As Double = 0

        If Page.IsValid Then
        Else
            Exit Sub
        End If
        DivisionID = CInt(hdnDivisionID.Value)
        DealerNumber = CType(hdnDealerNumber.Value, Int64)
        Dim ws As New CommonFunctions
        OrderID = ws.GetOrderID(DealerNumber, DivisionID)
        ItemID = CInt(lblItemID.Text)
        LNSPartNo = CStr(lblLNSPartNo.Text.Trim())
        KMSPartNo = CStr(lblKMSPartNo.Text.Trim())
        Qty = rntbQuantity.Value
        NetCost = rntbNetCost.Value
        If NetCost = CType(hdnNetCost.Value, Double) Then
            CostSource = CInt(hdnCostSource.Value)
        Else
            CostSource = 5
        End If
        OrderItemID = ws.InsertOrderItem(OrderID, ItemID, String.Empty, Qty, _
            NetCost, CostSource)
        ws = Nothing
    End Sub
End Class

how do I get the user control to close when it's done adding an item to the order?









7 Answers, 1 is accepted

Sort by
0
Elliott
Top achievements
Rank 2
answered on 28 Jun 2010, 05:29 PM
I realize that part of my problem is that Telerik doesn't have a Command called AddtoOrder
I changed it to Insert
still didn't close but at least it triggered something into the ItemCommand event of the calling program (Items.aspx)

I have my answer
even though I am adding to the OrderItem table, as far as the Items grid is concerned I triggered an Edit
so all I had to do was make the button send an Update command and voila - the window closed, the item added

0
D
Top achievements
Rank 1
answered on 28 Jul 2010, 08:38 PM

I'm having a similar issue. I've followed the code examples for using a WebUserControl, but on a PerformInsert command, I'm updating an nHibernate collection instead of creating a new row in a DataTable. I'm calling MasterViewTable.Rebind() to get the new row to display, which is working great. However, the grid opens a new instance of the UseControl right after. Is there some way to programmatically cancel an edit? I've tried firing an Update and a Cancel command immediatey after the call to Rebind, but neither worked.

<telerik:RadGrid ID="ExpenseDetailsGrid"
    SkinID="SubList"
    OnInsertCommand="OnInsertExpenseDetails"
    OnUpdateCommand="OnUpdateExpenseDetails"
    OnNeedDataSource="OnNeedDataSourceExpenseDetailsGrid"
    OnEditCommand="OnEditExpenseDetails"
    OnItemCommand="OnItemCommandRadGrid"
    runat="server">
    <MasterTableView CommandItemDisplay="Top" DataKeyNames="InvoiceDetailID">
        <Columns>
            <telerik:GridEditCommandColumn UniqueName="EditCommandColumn" EditText="Edit" HeaderText="Edit" />
            <telerik:GridBoundColumn UniqueName="DateColumn" HeaderText="Date" DataField="Created" />
            <telerik:GridBoundColumn UniqueName="MerchantColumn" HeaderText="Merchant" DataField="Title" />
            <telerik:GridBoundColumn UniqueName="ExpenseCategoryColumn" HeaderText="Expense Cateogry" DataField="InvoiceExpenseCategory.Title" />
            <telerik:GridBoundColumn UniqueName="PONumberLineItemColumn" HeaderText="PO Line Item" DataField="POLineItem.Title" />
            <telerik:GridBoundColumn UniqueName="AmountColumn" HeaderText="Amount" DataField="TotalLocal" />
            <telerik:GridButtonColumn UniqueName="DeleteColumn" Text="Delete" HeaderText="Delete" CommandName="Delete" />
        </Columns>
        <EditFormSettings UserControlName="expense_item_control.ascx" EditFormType="WebUserControl">
            <EditColumn UniqueName="EditCommandColumn" />
        </EditFormSettings>
    </MasterTableView>
    <ClientSettings>
        <ClientEvents OnRowDblClick="RowDblClick" />
    </ClientSettings>
</telerik:RadGrid>

protected void OnInsertExpenseDetails(object sender, GridCommandEventArgs e)
{
    expense_item_control itemControl = (expense_item_control)e.Item.FindControl(GridEditFormItem.EditFormUserControlID);
    itemControl.InsertInvoiceDetail(m_InvoiceHeader);
    m_InvoiceHeaderApi.Save(m_InvoiceHeader);
      
    ExpenseDetailsGrid.MasterTableView.Rebind();
    (e.Item as GridEditableItem).FireCommandEvent("Update", null);
}
0
Elliott
Top achievements
Rank 2
answered on 28 Jul 2010, 09:25 PM
I got my app to work by using the Edit command, then triggering an Update command
the grid (in part)
    <telerik:RadGrid ID="rgItems" AutoGenerateColumns="False" AllowPaging="True"
            AllowFilteringByColumn="True" AllowSorting="True" GridLines="None" runat="server">
        <GroupingSettings CaseSensitive="false" />
        <ClientSettings>
            <Scrolling AllowScroll="True" UseStaticHeaders="True"/>
        </ClientSettings>
        <MasterTableView DataKeyNames="ItemID" EditMode="PopUp">
        <ItemStyle CssClass="grid_item_style" />
        <AlternatingItemStyle CssClass="grid_alternating_item_style" />
        <Columns>
            <telerik:GridEditCommandColumn EditText="Add" UniqueName="btdAdd" ItemStyle-Width="30px" HeaderStyle-Width="30px" />
            <telerik:GridBoundColumn UniqueName="ItemID" DataField="ItemID" Visible="False">
            </telerik:GridBoundColumn>
more columns
        </Columns>
        <EditFormSettings UserControlName="OrderItem.ascx" EditFormType="WebUserControl">
        </EditFormSettings>
        </MasterTableView>
            <ClientSettings>
                <ClientEvents OnRowDblClick="RowDblClick" />
            </ClientSettings>
    </telerik:RadGrid>

at the bottom of the markup for the control:

<td>
    <asp:Button ID="btnCancel" Text="Cancel" CommandName="Cancel" CausesValidation="false" runat="server" />
</td>
<td align="right">
    <asp:Button ID="btnAddtoOrder" Text="Add to Order" CommandName="Update" runat="server" />
</td>

the event handler
    Protected Sub btnAddtoOrder_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAddtoOrder.Click
        Dim OrderID, DivisionID, ItemID, Qty, OrderItemID, CostSource As Integer
        Dim DealerNumber As Int64
        Dim LNSPartNo, KMSPartNo As String
        Dim NetCost As Double = 0
        If Page.IsValid Then
        Else
            Exit Sub
        End If
        DivisionID = CInt(hdnDivisionID.Value)
        DealerNumber = CType(hdnDealerNumber.Value, Int64)
        Dim ws As New CommonFunctions
        OrderID = ws.GetOrderID(DealerNumber, DivisionID)
        ItemID = CInt(lblItemID.Text)
        more kode
        OrderItemID = ws.InsertOrderItem(OrderID, ItemID, String.Empty, Qty, _
            NetCost, CostSource)
        ws = Nothing
    End Sub

0
D
Top achievements
Rank 1
answered on 28 Jul 2010, 09:59 PM
How is it you're using the Edit command for inserting a new item?
0
Elliott
Top achievements
Rank 2
answered on 28 Jul 2010, 10:09 PM
It's counterintuitive, I know

I am not inserting a new item into the grid - I am inserting to another table
it's an order entry application
the grid is parts (boat parts, not that it matters)
the "Add" or double-click issues an Edit command - but instead of the item to edit a user control pops up, with the ItemID and description filled in
the user fills in the quantity, then clicks Add to Order, which issues an Update command
the Update command event handler inserts an item into the OrderItem table - and closes the user control
I think the grid is smart enough to realize the data hasn't been updated and doesn't trigger a NeedDataSource event
0
D
Top achievements
Rank 1
answered on 28 Jul 2010, 10:24 PM
I'm essentially doing the same thing, except my OnClick handler for my Submit button is inserting a new nhibernate object into a collection. I figured out my issue though, essentially changing the Command from "PerformInsert" to "Update" did the trick for me as well, minus one step. I just had to tell the grid that I was no longer performing an insert.
protected void OnUpdateExpenseDetails(object sender, GridCommandEventArgs e)
{
    (e.Item as GridEditableItem).OwnerTableView.IsItemInserted = false;
}

When I tried doing this in the InsertCommand event handler, I was getting an exception for some bizarre reason. Since the UpdateCommand event handler accomplishes pretty much the same thing (I think it just automatically rebinds), I can get away with using that instead. Thanks for the inspiration!
0
Elliott
Top achievements
Rank 2
answered on 28 Jul 2010, 10:27 PM
glad to be of assistance
maybe you can fix my Reporting problem? :)
Tags
Grid
Asked by
Elliott
Top achievements
Rank 2
Answers by
Elliott
Top achievements
Rank 2
D
Top achievements
Rank 1
Share this question
or