Showing posts with label asp. Show all posts
Showing posts with label asp. Show all posts

Friday, May 11, 2012

How to block the execution thread using RadConfirm

Finally found a way to use the RadConfirm popup, which is invoked from client side, in combination with server side events. Following example will display the confirmation window and only continues to call the button click event IF the OK button is clicked by the user.


ASPX:


<telerik:RadWindowManager ID="RadWindowManager1" runat="server" EnableShadow="true">
</telerik:RadWindowManager>

<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
    <script type="text/javascript">

        var lastClickedItem = null;
        var clickCalledAfterRadprompt = false;
        var clickCalledAfterRadconfirm = false;

        function onClientButtonClicking(sender, args) {
            if (args.get_item().get_text() == "Order another beer") {
                if (!clickCalledAfterRadconfirm) {
                    args.set_cancel(true);
                    lastClickedItem = args.get_item();
                    radconfirm("Are you sure? You order it, you finish it!", confirmCallbackFunction);
                }
            }
        }

        function confirmCallbackFunction(args) {
            if (args) {
                clickCalledAfterRadconfirm = true;
                lastClickedItem.click();
            }
            else
            clickCalledAfterRadconfirm = false;
            lastClickedItem = null;
        }  

    </script>
</telerik:RadCodeBlock>

<CommandItemTemplate>
    <telerik:RadToolBar ID="RadToolBar1" runat="server" OnClientButtonClicking="onClientButtonClicking" OnButtonClick="RadToolBar1_ButtonClick" Width="100%">
        <CollapseAnimation Duration="200" Type="OutQuint" /> 
            <Items> 
                <telerik:RadToolBarButton CommandName="OrderBeer" runat="server" Text="Order another beer"></telerik:RadToolBarButton> 
            </Items> 
    </telerik:RadToolBar>
</CommandItemTemplate>

The CommandItemTemplate part you obviously need to add to your MasterTableView element..



CS:



protected void RadToolBar1_ButtonClick(object sender, RadToolBarEventArgs e)
    {
        RadToolBarButton button = e.Item as RadToolBarButton;
        if (button.CommandName == "OrderBeer")
        {
            \\Do stuff, drink the beer
            \\DrinkBeer();
        }
    }

Have a nice weekend folks!!!


Tuesday, April 10, 2012

Serverside RowClick event handling for RadGrid

Here are a few steps to handle an event on the server side for Telerik's RadGrid

1. Add attribute OnItemCommand to <Telerik:RadGrid>, for example "OnItemCommand="radGrid1_ItemCommand" if your grid name is radGrad1
2. Add attribute EnablePostBackOnRowClick="true" to <ClientSettings>
3. To your code behind, add the following, which will assign a specific cell value to a string:

protected void radGrid1_ItemCommand
{
    // this block will take the value of the column "ContactName" from the grid and assign it to a string
    if (e.CommandName == "RowClick")
    {
        int index = e.Item.ItemIndex;
        GridDataItem item = (GridDataItem)radGrid1.Items[index];
        string contactName = item["ContactName"].Text;
    }
}