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

Opening Rad Window Causes Postback

1 Answer 234 Views
Window
This is a migrated thread and some comments may be shown as answers.
Tracy
Top achievements
Rank 1
Tracy asked on 07 Feb 2011, 06:20 AM
Hi,

I have two questions regarding opening a rad window.  Please note in both scenario's I don't want to use the radalert or radconfirm dialog boxes, I want to be able to display my own message box.

First question, I have a page with a radgrid and am using linkbuttons in the CommandItemTemplate to perform add/updates/deletes and everything works great. When a user adds a new record, I perform validation that checks for a duplicate value against the database or a null value.  If a duplicate'null value is found then I open a radwindow that displays a message to the user that a duplicate/null value has been found and again this works great. The problem is that when the radwindow opens a postback occurs.  I don't want this to happen.

I have read the article Calling radalert from codebehind (all versions of RadWindow) and cannot figure out how top apply this to my code.  The scenario where I am calling the radwindow is a little different.  The code that opens the the rad window is in another module.

Here is the code that calls the radwindow;
<CommandItemTemplate >
                   <div style="padding: 5px 5px;">
                       <asp:LinkButton ID="lbtAdd"          runat="server" CommandName="InitInsert"     Visible='<%# Not rgvSecurityGroups.MasterTableView.IsItemInserted %>'><asp:Image ID="imgAdd" runat="server" CssClass="css_GFS01_Image_Align" ImageURL="<%$ Resources:Images,AddGreen16%>" /> Add </asp:LinkButton>  
                       <asp:LinkButton ID="btnEditSelected" runat="server" CommandName="EditSelected"   Visible='<%# rgvSecurityGroups.EditIndexes.Count = 0 and Not rgvSecurityGroups.MasterTableView.IsItemInserted %>'>          <asp:Image runat="server" CssClass="css_GFS01_Image_Align" ImageURL="<%$ Resources:Images, EditGreen16%>"/> Edit </asp:LinkButton>  
                       <asp:LinkButton ID="btnCancel"       runat="server" CommandName="CancelAll"      Visible='<%# rgvSecurityGroups.EditIndexes.Count > 0 Or rgvSecurityGroups.MasterTableView.IsItemInserted %>'><asp:Image ID="imgCancel" runat="server" CssClass="css_GFS01_Image_Align" ImageURL="<%$ Resources:Images,CancelGreen16%>" /> Cancel </asp:LinkButton>  
                       <asp:LinkButton ID="lbtSaveNew"      runat="server" CommandName="PerformInsert"  Visible='<%# rgvSecurityGroups.MasterTableView.IsItemInserted%>'><asp:Image ID="imgSaveNew" runat="server" CssClass="css_GFS01_Image_Align" ImageURL="<%$ Resources:Images,SaveButton18%>" /> Save New</asp:LinkButton>  
                       <asp:LinkButton ID="lbtDelete"       runat="server" CommandName="DeleteSelected" Visible='<%# rgvSecurityGroups.EditIndexes.Count = 0 and Not rgvSecurityGroups.MasterTableView.IsItemInserted %>'><asp:Image ID="imgDelete"       runat="server" CssClass="css_GFS01_Image_Align" ImageURL="<%$ Resources:Images,DeleteRed16%>" />Delete </asp:LinkButton>  
                       <asp:LinkButton ID="lbtSave"         runat="server" CommandName="UpdateEdited"   Visible='<%# rgvSecurityGroups.EditIndexes.Count > 0 or rgvSecurityGroups.MasterTableView.IsItemInserted%>'><asp:Image runat="server" CssClass="css_GFS01_Image_Align" ImageURL="<%$ Resources:Images,SaveBlue16%>" />  Update </asp:LinkButton>  
                       <asp:LinkButton ID="lbtRefresh"      runat="server" CommandName="RebindGrid"     ><asp:Image id="imgRefresh" runat="server" CssClass="css_GFS01_Image_Align" ImageURL="<%$Resources:Images, ReloadBlue16 %>" AlternateText ="Refresh Grid" /></asp:LinkButton>                     
                   </div>
               </CommandItemTemplate>


Private Sub rgvSecurityGroups_InsertCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles rgvSecurityGroups.InsertCommand
    Dim InsertedItem As GridDataInsertItem = DirectCast(e.Item.OwnerTableView.GetInsertItem(), GridDataInsertItem)
    Dim strSecurityGroup As String = DirectCast(InsertedItem("SecurityGroup").Controls(0), TextBox).Text
    Dim aryParameters(2) As String
    Dim strMessageType As String = Nothing
    Dim strMessage As String = Nothing
    Dim strMessageHeading As String = Nothing
    If strSecurityGroup Is Nothing Or IsDBNull(strSecurityGroup) Or Len(strSecurityGroup) = 0 Then
        strMessageType = "Error"
        strMessageHeading = "Null Value"
        aryParameters(0) = "Security Group"
        aryParameters(1) = strSecurityGroup
        strMessage = UDF_GetErrorMessage("Null Value", aryParameters)
        USB_DisplayMessage(strMessageType, strMessageHeading, strMessage, "Medium", "Black", Me.rwmMessageBox)
    Else
        If pUDF_DuplicateValueCheck(0, strSecurityGroup) = True Then
            strMessageType = "Error"
            strMessageHeading = "Duplicate Value"
            aryParameters(0) = "Security Group"
            aryParameters(1) = strSecurityGroup
            strMessage = UDF_GetErrorMessage("Duplicate Value", aryParameters)
            USB_DisplayMessage(strMessageType, strMessageHeading, strMessage, "Medium", "Black", Me.rwmMessageBox)
        Else
            Me.SQLDS_SecurityGroups.InsertCommandType = SqlDataSourceCommandType.Text
            Me.SQLDS_SecurityGroups.InsertCommand = "EXEC [Security].[DSP_SEL-INS-UPD-DEL-SecurityGroups] 'Insert', DEFAULT, " & strSecurityGroup
        End If
    End If

Here's is the code that opens the rad window, notice that I am sending the radwindow control that is used on the page that is calling the procedure.
Public Shared Sub USB_DisplayMessage(ByVal strMessageType As String, ByVal strMessageHeading As String, ByVal strMessage As String, ByVal strMessageSize As String, ByVal strSkin As String, ByVal rwmMessageBox As RadWindowManager)
       Dim rwdMessage As New RadWindow
       Dim strNavigation As String = "~/Modules/Central/WBF CTL Message Box.aspx?MessageType=" + strMessageType + "&MessageHeading=" + strMessageHeading + "&Message=" + strMessage
       rwdMessage.ID = "rwdMessageDetail"
       rwdMessage.Skin = strSkin
       Select Case strMessageSize
           Case "Small"
               rwdMessage.Height = "250"
               rwdMessage.Width = "400"
           Case "Medium"
               rwdMessage.Height = "300"
               rwdMessage.Width = "400"
       End Select
       rwdMessage.NavigateUrl = strNavigation
       rwmMessageBox.Windows.Add(rwdMessage)
   End Sub

So my question is how do I prevent the radwidow from causing a postback?

My second question is regarding the cancelling of the delete event.  As in the above scenario I am using the CommandItemTemplate with LinkButtons to perform all the record functions.  When the user clicks the delete button I open a radwindow prompting  (yes/no buttons)  them to confirm the deletion and again this works fine.  What I want to be able to do is Cancel the deletion if the user clicks the No button on the rad window.  But I can't figure out how to cancel the DeleteCommand if the user clicks the No button to cancel the deletion.

Here is the code that calls the rad window. The code for opening the rad window is the same as listed above.

Private Sub rgvSecurityGroups_DeleteCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles rgvSecurityGroups.DeleteCommand
    Dim GridItem As GridDataItem = DirectCast(e.Item, GridDataItem)
    Dim intSecurityId As Int16 = GridItem.GetDataKeyValue("SecurityID")
    Dim strSecurityGroup As String = GridItem("SecurityGroup").Text
    Dim strMessageType As String = Nothing
    Dim strMessage As String = Nothing
    Dim strMessageHeading As String = Nothing
    strMessageType = "Warning"
    strMessageHeading = "Deleting " + strSecurityGroup
    strMessage = "You have selected to delete security group " + strSecurityGroup & ".  This action will cause this group to be deleted from all Users.<br><br>Do you want to continue?"
    USB_DisplayMessage(strMessageType, strMessageHeading, strMessage, "Medium", "Black", Me.rwmMessageBox)
    Me.SQLDS_SecurityGroups.DeleteCommandType = SqlDataSourceCommandType.Text
    Me.SQLDS_SecurityGroups.DeleteCommand = "EXEC [Security].[DSP_SEL-INS-UPD-DEL-SecurityGroups] 'Delete', " & intSecurityId & ", DEFAULT"
End Sub

Thank you for your help.

1 Answer, 1 is accepted

Sort by
0
Georgi Tunev
Telerik team
answered on 08 Feb 2011, 01:37 PM
Hi Tracy,

Basically, if you are showing RadWindow from the server, it is expected to get a postback. To avoid it, you need to ajaxify the control that is calling the RadWindow and the RadWindow itself. For example, you could use RadAjaxManager.
Another approach is to hook to the client onclick event of the calling element - this approach is used in the Grid Editing demo (check the RadGrid1_ItemCreated event in codebehind).

I hope this information helps. If you need further assistance, it will be best to send us a sample project that isolates your setup so we can provide you with the most appropriate solution.


All the best,
Georgi Tunev
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Window
Asked by
Tracy
Top achievements
Rank 1
Answers by
Georgi Tunev
Telerik team
Share this question
or