display RadConfirm (Message) and capture response

2 posts, 0 answers
  1. Dan
    Dan avatar
    4 posts
    Member since:
    Apr 2014

    Posted 07 Jan Link to this post

    I have a radgrid with a CommandItemTemplate with three buttons. When a user clicks the 'Add Run' button it triggers the InitInsert.
    After the user enters the data and clicks the check image button to insert the data, a check is performed in the RadGrid.InsertCommand to see if the user entered a value in the Number column that already exists.  If the Number does exists the user needs to be prompted and asked if they want to renumber the already existing rows and insert this one, or cancel.

    I need to be able to display a message and capture the result and either exit the sub or do other processing.

     

    Some script attempts

           //function confirmCallBackFn(arg) {
            //    radalert("<strong>radconfirm</strong> returned the following result: <h3 style='color: #ff0000;'>" + arg + "</h3>", 350, 250, "Result");
            //}
            function RadResequence(sender, args) {
                var callBackFunction = Function.createDelegate(sender, function (shouldSubmit) {
                    if (shouldSubmit) {
                        this.click();
                    }
                });
                var text = "<%= ResequenceAssignments %>";;
                radconfirm(text, callBackFunction, 500, 100, null, "Confirm Close");
                args.set_cancel(true);
            }


            function RadResequence2() {
                var confirmValue = document.createElement("INPUT");
                confirmValue.type = "hidden";
                confirmValue.name = "confirmValue";
                if (confirm("Do you want to Resequence? If you click yes, blah blah blah")) {
                    confirmValue.value = "OK";
                }
                else {
                    confirmValue.value = "Cancel";
                }
                document.forms[0].appendChild(confirmValue);
            }

     

     

     

    THE RADGRID

    <telerik:RadGrid ID="rdgrdDetailRS" OnSelectedIndexChanged="rdgrdDetailRS_SelectedIndexChanged" ClientSettings-EnablePostBackOnRowClick="true" runat="server" Width="275" AutoGenerateColumns="false" AllowPaging="true" PageSize="75" AllowFilteringByColumn="false" GridLines="Horizontal" CssClass="ctbGridHeader" AllowAutomaticUpdates="false">
                                        <GroupingSettings CaseSensitive="False" />
                                        <SelectedItemStyle CssClass="MySelectedClass" />
                                        <ClientSettings>
                                            <Selecting AllowRowSelect="True" />
                                            <Resizing EnableNextColumnResize="false" />
                                            <Scrolling AllowScroll="true" UseStaticHeaders="true" SaveScrollPosition="true" />
                                        </ClientSettings>
                                        <%--<MasterTableView DataKeyNames="DateCode, Number, Assigned" CommandItemDisplay="Top" EditMode="InPlace">--%>
                                        <MasterTableView DataKeyNames="DateCode, Number, Assigned" CommandItemDisplay="Top">
                                            <AlternatingItemStyle CssClass="MyRowClass" />
                                            <CommandItemTemplate>
                                                a a                                          
                                                <div id="divButtons" style="padding: 5px 0 5px 5px">
                                                    <telerik:RadButton ID="btnAddAssignment" OnClientClicking="RadCreateRequest" runat="server" Text="Insert Assignment" CommandName="InsertAssignment">
                                                    </telerik:RadButton>
                                                    <%--<telerik:RadButton ID="btnAddRun" runat="server" Text="Add Run" CommandName="AddRun">
                                                    </telerik:RadButton>--%>
                                                    <telerik:RadButton ID="btnAddRun" runat="server" Text="Add Run" CommandName="InitInsert">
                                                    </telerik:RadButton>
                                                    <telerik:RadButton ID="btnSplitRun" runat="server" Text="Split Run" CommandName="SplitRun">
                                                    </telerik:RadButton>
                                                </div>
                                            </CommandItemTemplate>
                                            <Columns>
                                                <telerik:GridBoundColumn DataField="DateCode" Display="false" FilterControlAltText="Filter colDateCode column" UniqueName="colDateCode" ReadOnly="True">
                                                    <ColumnValidationSettings>
                                                        <ModelErrorMessage Text="" />
                                                    </ColumnValidationSettings>
                                                </telerik:GridBoundColumn>
                                                <telerik:GridEditCommandColumn FilterControlAltText="Filter EditCommandColumn column"
                                                    ButtonType="ImageButton">
                                                    <ItemStyle Width="3%" />
                                                </telerik:GridEditCommandColumn>
                                                <telerik:GridBoundColumn DataField="Number" FilterControlAltText="Filter colBusNumber column" UniqueName="colBusNumber" HeaderText="Number" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" ShowFilterIcon="false"
                                                    FilterControlToolTip="Press Enter or Tab key to search for value entered." FilterControlWidth="98%" ReadOnly="True">
                                                    <HeaderStyle HorizontalAlign="Center" />
                                                </telerik:GridBoundColumn>
                                                <telerik:GridTemplateColumn DataField="Assigned" HeaderText="Assigned" UniqueName="Assigned">
                                                    <ItemTemplate>
                                                        <%#DataBinder.Eval(Container.DataItem, "Assigned")%>
                                                    </ItemTemplate>
                                                    <EditItemTemplate>
                                                        <telerik:RadComboBox ID="cmbActiveDrivers" EmptyMessage="" runat="server" Width="100%" Text='<%# Bind("Assigned") %>' DataSourceID="dsActiveDrivers" DataValueField="FullName" DataTextField="FullName">
                                                        </telerik:RadComboBox>
                                                    </EditItemTemplate>
                                                </telerik:GridTemplateColumn>
                                                <telerik:GridButtonColumn ConfirmText="Delete this details record?" ButtonType="ImageButton"
                                                    CommandName="Delete" Text="Delete" UniqueName="DeleteColumn2">
                                                    <ItemStyle HorizontalAlign="Center" CssClass="MyImageButton" Width="3%" />
                                                </telerik:GridButtonColumn>
                                            </Columns>
                                            <EditFormSettings EditColumn-ButtonType="ImageButton">
                                            </EditFormSettings>
                                        </MasterTableView>
                                    </telerik:RadGrid>

     

     

    THE RADGRID.INSERTCOMMAND SUB. I'm just worried about the For next loop checking for a duplicate value in the radgrid then displaying a message and capturing the result.

     

        Private Sub rdgrdDetailRS_InsertCommand(sender As Object, e As GridCommandEventArgs) Handles rdgrdDetailRS.InsertCommand
            If TypeOf e.Item Is GridEditableItem Then
                Dim insertedItem As Telerik.Web.UI.GridEditableItem = CType(e.Item, Telerik.Web.UI.GridEditableItem)
                Dim newValues As Hashtable = New Hashtable
                e.Item.OwnerTableView.ExtractValuesFromItem(newValues, insertedItem)
                Try
                    Dim strNewValue As String = newValues("Assigned").ToString
                    Dim strID2 As String = newValues("Number").ToString
                    If Len(strID2) <> 2 Then
                        rwmAdministration.RadAlert("Number must be Two digtis Only.", 500, 100, "Add Error", "null")
                        Exit Sub
                    End If
                    If Not IsNumeric(strID2) Then
                        rwmAdministration.RadAlert("Number must be a numerical value.", 500, 100, "Add Error", "null")
                        Exit Sub
                    End If
                    For Each row In rdgrdDetailRS.Items
                        If row.Cells(4).text = strID2 Then
                            'TODO need to figure out how to ask the user if they want ot resequence
                            ' rwmAdministration.RadAlert("Sorry, Run number " & strID2 & " already exists. Do you want to resequence", 500, 100, "Add Error", "null")
                            '  rwmAdministration.RadConfirm("Server radconfirm: Are you sure?", "confirmCallBackFn", 330, 180, Nothing, "Server RadConfirm", Nothing)
                            ' rwmAdministration.RadConfirm("Do you want to resequence. Are you sure?", "RadResequence", 330, 180, Nothing, "Server RadConfirm", Nothing)
                            rwmAdministration.RadConfirm("Do you want to resequence. Are you sure?", "RadResequence2", 330, 180, Nothing, "Server RadConfirm", Nothing)
                            Dim confirmValue As String = Request.Form("confirmValue")
                            If confirmValue = "Ok" Then
                                Dim value As String = "Ok"
                            Else
                                Dim value As String = "Cancel"
                            End If
                            ' Exit Sub
                        End If
                    Next




                    Dim cmd As New SqlCommand
                    cmd.CommandType = CommandType.StoredProcedure
                    cmd.CommandText = "InsertDetailRS"
                    cmd.Parameters.Add(New SqlParameter("@DateCode", SqlDbType.Date)).Value = BasicUtil.GetQueryString 'CType(strID, Date)
                    cmd.Parameters.Add(New SqlParameter("@Number", SqlDbType.VarChar)).Value = CType(strID2, String)
                    cmd.Parameters.Add(New SqlParameter("@LastModifiedBy", SqlDbType.NVarChar)).Value = ADUtil.GetCurrentUser
                    ' cmd.Parameters.Add(New SqlParameter("@ID", SqlDbType.Date)).Value = BasicUtil.GetQueryString
                    cmd.Parameters.Add(New SqlParameter("@Assigned", SqlDbType.NVarChar)).Value = strNewValue
                    Dim bolOk As Boolean = SQLUtil.ExecuteNonQuery(cmd, BasicUtil.csAppDB)
                    If bolOk Then
                        rdgrdDetailRS.Rebind()
                    Else
                        rwmAdministration.RadAlert("There was an error trying to insert a New Run record.", 500, 100, "Update Error", "null")
                        e.Canceled = True
                    End If
                    ' Else
                    '  rdgrdDetailRS.Rebind()
                    'End If
                Catch ex As Exception
                    e.Canceled = True
                    rwmAdministration.RadAlert("There was an error trying to insert a New Run record.", 500, 100, "Update Error", "null")
                End Try
                rdgrdDetailRS.Rebind()
            End If
        End Sub

  2. Dan
    Dan avatar
    4 posts
    Member since:
    Apr 2014

    Posted 08 Jan Link to this post

    I did the hidden button thing.

     

    Create   this function

    function confirmCallbackFn(arg) {
    if (arg) //the user clicked OK
    {
    __doPostBack("<%=HiddenButton.UniqueID %>", "");
    }
    }

    Add a Hidden button, call it what you want

    </telerik:RadWindowManager>
    <asp:Button ID="HiddenButton" Text="" Style="display: none;" OnClick="HiddenButton_Click" runat="server" />

     

    Display a RadConfirm in the middle of the code that is processing. Call the javascript function confirmCallbackFn. You have to remember all your server code will run until completion before the message gets displayed.

    rwmAdministration.RadConfirm("The Run Number Already Exists, Do you want to Resequence?", "confirmCallbackFn", 300, 200, Nothing, "Confirm")

     

    If the user clicks ok then the Click event gets called otherwise processing stops.

    Protected Sub HiddenButton_Click(sender As Object, e As System.EventArgs) Handles HiddenButton.Click
           'Handle the response here and execute the rest of the logic

    End Sub

     

Back to Top