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

RadAlert,RadGrid and UserCONTROL

1 Answer 108 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Robert Jakech
Top achievements
Rank 1
Robert Jakech asked on 22 Mar 2010, 07:22 PM
I have a radgrid from which i insert/edit records via a usercontrol.

In my code behind, i want to call RadAlert when my textbox is empty.
I have read alot of examples and non of them suites my problem.
Here is the code 

.ASPX(page)
<%@ Page Language="C#" MasterPageFile="~/Resources/MasterPages/Parameters.Master" AutoEventWireup="true" CodeFile="Intake.aspx.cs" Inherits="WebForms_Intake" Title="Intake" %>
<%@ Register assembly="RadGrid.Net2" namespace="Telerik.WebControls" tagprefix="rad" %>


<asp:Content ID="Content2" ContentPlaceHolderID="PageBody" Runat="Server" >
    <h2>Intake</h2>    
    <rad:RadGrid ID="IntakeGrid" runat="server" OnNeedDataSource="IntakeRadGrid_NeedDataSource" 
    OnDeleteCommand="IntakeRadGrid_DeleteCommand"  AllowPaging="True" 
        AllowSorting="True" AutoGenerateColumns="False" 
         EnableAJAX="True" GridLines="None" 
        RadControlsDir="~/Resources/RadControls/" Skin="Web20" 
        SkinsPath="~/Resources/RadControls/Grid/Skins" Width="750px">
        <MasterTableView AllowMultiColumnSorting="True" DataKeyNames="Id" 
             CommandItemDisplay="Top">
            <RowIndicatorColumn>
                <HeaderStyle Width="20px"></HeaderStyle>
            </RowIndicatorColumn>
            <ExpandCollapseColumn>
                <HeaderStyle Width="20px"></HeaderStyle>
            </ExpandCollapseColumn>
            <Columns>
                <rad:GridEditCommandColumn ButtonType="ImageButton" 
                    EditImageUrl="~/Resources/Buttons/EditButton.jpg" >
                </rad:GridEditCommandColumn>
                <rad:GridBoundColumn DataField="Id" HeaderText="ID" 
                    SortExpression="Id" UniqueName="Id">
                </rad:GridBoundColumn>
                <rad:GridBoundColumn DataField="IntakeName" HeaderText="Intake" 
                    SortExpression="IntakeName" UniqueName="Intake">
                </rad:GridBoundColumn>
                <rad:GridButtonColumn ButtonType="ImageButton" CommandName="Delete" 
                    ImageUrl="~/Resources/Buttons/DeleteButton.jpg"  Text="Delete" UniqueName="column">
                </rad:GridButtonColumn>
                
            </Columns>

                    <EditFormSettings EditFormType="WebUserControl" UserControlName="~/UserControls/Parameters/EditIntake.ascx" >
                        <EditColumn UniqueName="EditIntakeGrid" >
                        </EditColumn>
                    </EditFormSettings>
        </MasterTableView>
    </rad:RadGrid>
    
       

</asp:Content>
.ASPX.CS
using System;
using System.Collections;
using System.Configuration;
using System.Data;
 
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Telerik.WebControls;
using ARIMS.BusinessLogic;

    public partial class WebForms_Intake : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindRecords();

            }
        }


        protected void BindRecords()
        {
            IntakeGrid.DataSource = (object)ParameterManager.IntakeCollection();
            IntakeGrid.DataBind();


        }

        protected void IntakeRadGrid_NeedDataSource(object source, Telerik.WebControls.GridNeedDataSourceEventArgs e)
        {
            IntakeGrid.DataSource = (object)ParameterManager.IntakeCollection();

        }

        protected void IntakeRadGrid_DeleteCommand(object source, Telerik.WebControls.GridCommandEventArgs e)
        {
            //Get the GridDataItem of the RadGrid     
            GridDataItem item = (GridDataItem)e.Item;
            //Get the primary key value using the DataKeyValue.     
            int IntakeID = Convert.ToInt32(item.OwnerTableView.DataKeyValues[item.ItemIndex]["Id"].ToString());
            try
            {

                ParameterManager.IntakeDelete(IntakeID);
            }
            catch (Exception ex)
            {
                IntakeGrid.Controls.Add(new LiteralControl("Unable to Delete Record. Reason: " + ex.Message));
                e.Canceled = true;
            }

        }



    }
.ASCX
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="EditIntake.ascx.cs"
    Inherits="WebForms_EditIntake" %>
<%@ Register Assembly="RadInput.Net2" Namespace="Telerik.WebControls" TagPrefix="rad" %>
<table>
    <tr>
        <td>
            <asp:Label ID="lblIntake" runat="server">Intake:</asp:Label>
        </td>
        <td>
            <rad:RadTextBox ID="IntakeTextBox" Text='<%# Eval("IntakeName") %>' runat="server"
                Skin="Web20" SkinsPath="~/Resources/RadControls/Input/Skins">
            </rad:RadTextBox>
            <asp:RequiredFieldValidator ID="RequiredIntakeTextBox" ValidationGroup="validD" runat="server" ErrorMessage="<br>* Required"
                                    ControlToValidate="IntakeTextBox"></asp:RequiredFieldValidator>
        </td>
    </tr>
    <tr>
        <td>
            <asp:ImageButton ID="LinkInsert" ValidationGroup="validD" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
                ImageUrl="~/Resources/Buttons/SaveButton.jpg" runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'
                OnClick="IntakeInsert" Visible='<%# (Container is GridEditFormInsertItem) ? true : false %>' />
            <asp:ImageButton ID="LinkUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
                ImageUrl="~/Resources/Buttons/SaveButton.jpg" runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'
                OnClick="IntakeUpdate" Visible='<%# (Container is GridEditFormInsertItem) ? false : true %>' />
            <asp:ImageButton ID="LinkButtonCancel" ImageUrl="~/Resources/Buttons/CancelButton.jpg"
                runat="server" Text="Cancel" CausesValidation="false" CommandName="Cancel" />
        </td>
    </tr>
    <tr>
        <td>
            <rad:RadTextBox ID="IDTextBox" Text='<%# Eval("Id") %>' runat="server" Skin="Web20"
                Visible="false" SkinsPath="~/Resources/RadControls/Input/Skins">
            </rad:RadTextBox>
        </td>
    </tr>
</table>

.ASCX.CS
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Telerik.QuickStart;
using Telerik.WebControls;
using ARIMS.BusinessLogic;


public partial class WebForms_EditIntake : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void IntakeInsert(object sender, EventArgs e)
    {
        ParameterManager.IntakeInsert(IntakeTextBox.Text);
    }

    protected void IntakeUpdate(object sender, EventArgs e)
    {
        ParameterManager.IntakeUpdate(Convert.ToInt32(IDTextBox.Text), IntakeTextBox.Text);
    }
}

Now, What i want to do is within Protected void IntakeUpdate(object sender, EventArg e) method.

I want to write something like

If(IntakeTextBox.Text==String.Empty)
{
RadAjaxManager1.ResponseScripts.Add(@"radalert('You can't update empty fields <b>Prometheus</b>!', 330, 210);");
}
else
{
//Update the records
}

I need to return an alert.
But when i click the button, nothing happens.

Please, I desperately need your help.

thanks.

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 23 Mar 2010, 12:53 PM
Hi,

Please  have  a look at the help link below:

Princy
Tags
Grid
Asked by
Robert Jakech
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or