How to write javascript on controls in Edit Template of FormView

7 posts, 0 answers
  1. Shyam
    Shyam avatar
    5 posts
    Member since:
    Feb 2014

    Posted 04 Feb 2014 Link to this post

    Hi There,

    I was trying to find CheckBox in the form using below code. When user clicks on the "SAVE" button, if user does not check checkbox in the form, it should ask user to select the "CheckBox" using Message box(Yes\No). If user selects "Yes" then it should automatically check the CheckBox. Please help. 

    ASPX file

    <%@ Page Title="" Language="C#" MasterPageFile="~/DefaultMaster.master" AutoEventWireup="true" CodeFile="ContentDetail.aspx.cs" Inherits="ContentDetailPage" %>
    <%@ MasterType VirtualPath="~/DefaultMaster.master" %>

    <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <script type="text/javascript">
    function CheckBeforeDelete(sender, args) {
    args.set_cancel(!window.confirm("Are you sure you would like to delete this record?"));
    }
    </script>
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" Skin="Default" runat="server"
    MinDisplayTime="1000" InitialDelayTime="0">
    </telerik:RadAjaxLoadingPanel>

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

    <telerik:RadWindow ID="confirmWindow" runat="server" VisibleTitlebar="true" VisibleStatusbar="false"
    Modal="true" Behaviors="None" Height="150px" Width="300px">
    <ContentTemplate>
    <div style="padding-left: 30px; padding-top: 20px; width: 200px; float: left;">
    <asp:Label ID="lblConfirm" Font-Size="14px" Text="Is this the Content change?" runat="server"></asp:Label>
    <br />
    <br />
    <telerik:RadButton ID="RadButtonYes" runat="server" Text="Yes" AutoPostBack="false"
    OnClientClicked="confirmResult" >
    </telerik:RadButton>

    <telerik:RadButton ID="RadButtonNo" runat="server" Text="No" AutoPostBack="false"
    OnClientClicked="confirmResult">
    </telerik:RadButton>
    </div>
    </ContentTemplate>
    </telerik:RadWindow>

    <asp:FormView ID="FormView1" runat="server" DataKeyNames="ContentId" DefaultMode="Edit"
    DataSourceID="DocumentContentDataSource" ondatabound="FormView1_DataBound"
    onitemdeleted="FormView1_ItemDeleted" onprerender="FormView1_PreRender"
    >
    <EditItemTemplate>
    <asp:HiddenField ID="HiddenField1" runat="server" Value='<%# Bind("VersionId") %>' />
    <asp:HiddenField ID="HiddenField3" runat="server" Value='<%# Bind("ParentContentId") %>' />
    <asp:HiddenField ID="HiddenField5" runat="server" Value='<%# Bind("Level") %>' />
    <asp:HiddenField ID="HiddenField6" runat="server" Value='<%# Bind("CreatedBy") %>' />
    <asp:HiddenField ID="HiddenField2" runat="server" Value='<%# Bind("CreatedDate") %>' />
    <asp:HiddenField ID="HiddenField8" runat="server" Value='<%# Bind("LastUpdatedBy") %>' />
    <asp:HiddenField ID="HiddenField7" runat="server" Value='<%# Bind("LastUpdatedDate") %>' />
    <asp:HiddenField ID="HiddenField4" runat="server" Value='<%# Bind("SortNo") %>' />
    <asp:HiddenField ID="HiddenField9" runat="server" Value='<%# Bind("HierarchySortNo") %>' />
    <table>
    <tr style="height:30px">
    <td>
    <span class="label">Context:&nbsp;</span>
    </td>
    <td>
    <asp:Label ID="LabelParent" CssClass="label" runat="server" />
    </td>
    </tr>
    <tr>
    <td>
    <span class="label">Section Type:</span>
    </td>
    <td>
    <asp:Label ID="LabelSectionType" CssClass="label" Text='<%# Eval("SectionType") %>' runat="server" />
    </td>
    </tr>
    <tr>
    <td>
    <span class="label">Section Name:&nbsp;</span>
    </td>
    <td>
    <telerik:RadTextBox ID="RadTextBoxContentName" Width="450px" Runat="server"
    Text='<%# Bind("ContentName") %>'>
    </telerik:RadTextBox>&nbsp;&nbsp;
    <telerik:RadButton ID="RadButtonIsMandatory" runat="server" Text="Mandatory" ToggleType="CheckBox"
    ButtonType="ToggleButton" Checked='<%# Bind("IsMandatory") %>' Width="60px">
    </telerik:RadButton>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" Display="Dynamic"
    ControlToValidate="RadTextBoxContentName" ErrorMessage="Enter a section name"
    CssClass="validate-warning">
    </asp:RequiredFieldValidator>
    </td>
    </tr>
    <tr>
    <td>
    <span class="label">Section Title:&nbsp;</span>
    </td>
    <td>
    <telerik:RadTextBox ID="RadTextBoxContentLabel" Width="450px" Runat="server"
    Text='<%# Bind("ContentLabel") %>'>
    </telerik:RadTextBox>&nbsp;&nbsp;
    <telerik:RadButton ID="RadButtonContentChanged" runat="server" Text="Content Change?" ToggleType="CheckBox"
    ButtonType="ToggleButton" Checked='<%# Bind("ContentChangedInd") %>' Width="95px">
    </telerik:RadButton>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" Display="Dynamic"
    ControlToValidate="RadTextBoxContentLabel" ErrorMessage="Enter a section title"
    CssClass="validate-warning">
    </asp:RequiredFieldValidator>

    </td>
    </tr>
    </table>
    <table style="margin-top:10px">
    </table>
    <table style="margin-top:10px">
    <tr>
    <td>
    <span class="label">Created:&nbsp;</span>
    </td>
    <td>
    <asp:Label ID="Label1" CssClass="label" runat="server"
    Text='<%# Eval("CreatedByUser.DisplayName") + " On " + Eval("CreatedDate") %>' />
    </td>
    <td style="padding-left:30px">
    <span class="label">Last Updated:&nbsp;</span>
    </td>
    <td>
    <asp:Label ID="Label2" CssClass="label" runat="server"
    Text='<%# Eval("LastUpdatedByUser.DisplayName") + " On " + Eval("LastUpdatedDate") %>' />
    </td>
    </tr>
    </table>
    <div style="margin-top:10px">
    <table>
    <tr>
    <td>
    <telerik:RadEditor ID="RadEditor1" runat="server" Content='<%# Bind("Content") %>'
    StripFormattingOptions="MsWord,Span,Css,ConvertWordLists" Width="625px" ToolsFile="~/RadEditorToolsFile.xml" ImageManager-ViewPaths="~/UserImages">
    <CssFiles>
    <telerik:EditorCssFile Value="~/Styles/radeditor.css" />
    </CssFiles>
    <Tools>
    <telerik:EditorToolGroup>
    <telerik:EditorTool Name="InsertDocumentLink" Text="Insert Within Document Link" />
    </telerik:EditorToolGroup>
    </Tools>
    </telerik:RadEditor>
    <script type="text/javascript">
    Telerik.Web.UI.Editor.CommandList["InsertDocumentLink"] = function (commandName, editor, args) {

    var myCallbackFunction = function (sender, args) {
    editor.pasteHtml(String.format("<a href=#{0}>{1}</a> ", args.templateId, args.label))
    }

    editor.showExternalDialog(
    'DocumentLinkBuilder.aspx',
    null,
    350,
    300,
    myCallbackFunction,
    null,
    'Insert Document Link',
    true,
    Telerik.Web.UI.WindowBehaviors.Close + Telerik.Web.UI.WindowBehaviors.Move,
    true,
    true);
    };

    function showConfirmRadWindow(sender, args) {

    $find("<%=confirmWindow.ClientID %>").show();

    $find("<%=RadButtonYes.ClientID %>").focus();

    args.set_cancel(true);

    }


    function confirmResult(sender, args) {

    var oWnd = $find("<%=confirmWindow.ClientID %>");

    oWnd.close();

    if (sender.get_text() == "Yes") {

    //var CheckBoxContentChange = '<%=FormView1.FindControl("RadButtonContentChanged").ClientID%>'
    //var CheckBoxContentChange = document.getElementById('<%=FormView1.FindControl("RadButtonContentChanged").ClientID%>');
    var CheckBoxContentChange = '<%= DirectCast(FormView1.FindControl("RadButtonContentChanged").ClientID)%>'
    alert(CheckBoxContentChange);

    //$find("<%=RadButtonYes.ClientID %>").click();

    }

    }

    //This code need to be deleted
    //function confirmCallBackFn(arg) {
    // alert(arg);
    //}

    </script>
    </td>
    <td style="padding-left:15px; vertical-align:top">
    <asp:Panel ID="PanelBusinessLineDocumentContent" runat="server">
    <div class="section" style="width:475px">
    <div class="section-header">
    <span class="label">LOB Applicable</span>
    </div>
    <div style="padding:5px">
    <table>
    <tr>
    <td>
    <telerik:RadComboBox ID="RadComboBoxBusinessLine" runat="server"
    DataTextField="BusinessLineName" DataValueField="BusinessLineId" Width="300px">
    </telerik:RadComboBox>
    <telerik:RadButton ID="RadButtonAddBusinessLine" runat="server" Text="Add"
    onclick="RadButtonAddBusinessLine_Click" Width="60px" CssClass="document-maint-detail-oneoff">
    </telerik:RadButton>
    <telerik:RadButton ID="RadButtonAddAllBusinessLine" runat="server" Text="Add All"
    onclick="RadButtonAddAllBusinessLine_Click" Width="60px" CssClass="document-maint-detail-oneoff">
    </telerik:RadButton>
    </td>
    </tr>
    <tr>
    <td style="padding-top:5px">
    <telerik:RadGrid ID="RadGridBusinessLineDocumentContent" runat="server"
    AutoGenerateColumns="False" GridLines="None" Height="330px" Width="460px">
    <ClientSettings>
    <Scrolling AllowScroll="True" UseStaticHeaders="True" />
    </ClientSettings>
    <MasterTableView DataKeyNames="BusinessLineId">
    <Columns>
    <telerik:GridTemplateColumn>
    <HeaderTemplate>
    <asp:LinkButton ID="LinkButtonRemove" runat="server" Text="Remove"
    OnClick="LinkButtonRemoveAllBusinessLines_Click" ToolTip="Click to remove all">
    </asp:LinkButton>
    </HeaderTemplate>
    <ItemTemplate>
    <asp:LinkButton ID="LinkButtonRemove" runat="server" CommandArgument='<%# Eval("BusinessLineId") %>'
    Text="Remove" OnClick="LinkButtonRemoveBusinessLine_Click">
    </asp:LinkButton>
    </ItemTemplate>
    </telerik:GridTemplateColumn>
    <telerik:GridBoundColumn DataField="BusinessLineId" Visible="false" UniqueName="BusinessLineId" />
    <telerik:GridBoundColumn DataField="BusinessLineName" HeaderText="Business Line" UniqueName="BusinessLineName" />
    <telerik:GridBoundColumn DataField="ApplicableText" HeaderText="Applicable?" UniqueName="ApplicableText">
    <ItemStyle Width="75px" />
    </telerik:GridBoundColumn>
    </Columns>
    <NoRecordsTemplate>
    <i><span style="padding-left:2px">No business lines apply</span></i>
    </NoRecordsTemplate>
    </MasterTableView>
    </telerik:RadGrid>
    </td>
    </tr>
    </table>
    </div>
    </div>
    </asp:Panel>
    </td>
    </tr>
    </table>
    </div>
    <br />
    <telerik:RadButton ID="RadButtonSave" runat="server" Text="Save" ButtonType="LinkButton"
    CommandName="Update" CausesValidation="true" CssClass="std-button"
    OnClientClicking="showConfirmRadWindow"
    >
    </telerik:RadButton>
    <telerik:RadButton ID="RadButtonDelete" runat="server" Text="Delete" ButtonType="LinkButton"
    CommandName="Delete" CausesValidation="True" CssClass="std-button" OnClientClicking="CheckBeforeDelete">
    </telerik:RadButton>&nbsp;
    <telerik:RadButton ID="RadButtonCancel" runat="server" Text="Back" ButtonType="LinkButton"
    CommandName="Cancel" CausesValidation="False" CssClass="std-button" onclick="RadButtonCancel_Click">
    </telerik:RadButton>&nbsp;
    <telerik:RadButton ID="RadButtonAddNew" runat="server" Text="Add New" ButtonType="LinkButton"
    CausesValidation="False" CssClass="std-button" NavigateUrl="~/Content/ContentDetail.aspx">
    </telerik:RadButton>
    </EditItemTemplate>
    <InsertItemTemplate>
    <table>
    <tr>
    <td>
    <span class="label">Version:&nbsp;</span>
    </td>
    <td>
    <telerik:RadTextBox ID="RadTextBoxVersion" Width="200px" Runat="server" Enabled="false">
    </telerik:RadTextBox>
    </td>
    </tr>
    <tr>
    <td>
    <span class="label">Section Name:&nbsp;</span>
    </td>
    <td>
    <telerik:RadTextBox ID="RadTextBoxContentName" Width="450px" Runat="server"
    Text='<%# Bind("ContentName") %>'>
    </telerik:RadTextBox>&nbsp;&nbsp;
    <telerik:RadButton ID="RadButtonIsMandatory" runat="server" Text="Mandatory" ToggleType="CheckBox"
    ButtonType="ToggleButton" Checked='<%# Bind("IsMandatory") %>' Width="60px">
    </telerik:RadButton>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" Display="Dynamic"
    ControlToValidate="RadTextBoxContentName" ErrorMessage="Enter a section name"
    CssClass="validate-warning" ValidationGroup="OnInsert">
    </asp:RequiredFieldValidator>
    </td>
    </tr>
    <tr>
    <td>
    <span class="label">Section Title:&nbsp;</span>
    </td>
    <td>
    <telerik:RadTextBox ID="RadTextBoxContentLabel" Width="450px" Runat="server"
    Text='<%# Bind("ContentLabel") %>'>
    </telerik:RadTextBox>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" Display="Dynamic"
    ControlToValidate="RadTextBoxContentLabel" ErrorMessage="Enter a section title"
    CssClass="validate-warning" ValidationGroup="OnInsert">
    </asp:RequiredFieldValidator>
    </td>
    </tr>
    <tr>
    <td>
    <span class="label">Chapter:&nbsp;</span>
    </td>
    <td>
    <telerik:RadComboBox ID="RadComboBoxChapter" runat="server"
    DataTextField="ContentLabel" DataValueField="ContentId"
    AutoPostBack="true" AppendDataBoundItems="true"
    onselectedindexchanged="RadComboBoxChapter_SelectedIndexChanged">
    <Items>
    <telerik:RadComboBoxItem Text="" Value="-1" />
    </Items>
    </telerik:RadComboBox>
    </td>
    </tr>
    <tr>
    <td>
    <span class="label">Heading:&nbsp;</span>
    </td>
    <td>
    <telerik:RadComboBox ID="RadComboBoxHeading" runat="server"
    DataTextField="ContentLabel" DataValueField="ContentId"
    AutoPostBack="true" AppendDataBoundItems="true">
    <Items>
    <telerik:RadComboBoxItem Text="" Value="-1" />
    </Items>
    </telerik:RadComboBox>
    </td>
    </tr>
    </table>
    <div style="margin-top:10px">
    <telerik:RadEditor ID="RadEditor1" runat="server" Content='<%# Bind("Content") %>'
    StripFormattingOptions="MsWord,Span,Css,ConvertWordLists">
    <CssFiles>
    <telerik:EditorCssFile Value="~/Styles/radeditor.css" />
    </CssFiles>
    </telerik:RadEditor>
    </div>
    <br />
    <telerik:RadButton ID="RadButtonSave" runat="server" Text="Save" ButtonType="LinkButton"
    CommandName="Insert" CausesValidation="true" CssClass="std-button" ValidationGroup="OnInsert" >
    </telerik:RadButton>&nbsp;
    <telerik:RadButton ID="RadButtonCancel" runat="server" Text="Back" ButtonType="LinkButton"
    CommandName="Cancel" CausesValidation="False" CssClass="std-button" onclick="RadButtonCancel_Click">
    </telerik:RadButton>
    </InsertItemTemplate>
    <ItemTemplate>
    <asp:HiddenField ID="HiddenField1" runat="server" Value='<%# Bind("VersionId") %>' />
    <asp:HiddenField ID="HiddenField3" runat="server" Value='<%# Bind("ParentContentId") %>' />
    <asp:HiddenField ID="HiddenField5" runat="server" Value='<%# Bind("Level") %>' />
    <asp:HiddenField ID="HiddenField6" runat="server" Value='<%# Bind("CreatedBy") %>' />
    <asp:HiddenField ID="HiddenField2" runat="server" Value='<%# Bind("CreatedDate") %>' />
    <asp:HiddenField ID="HiddenField8" runat="server" Value='<%# Bind("LastUpdatedBy") %>' />
    <asp:HiddenField ID="HiddenField7" runat="server" Value='<%# Bind("LastUpdatedDate") %>' />
    <asp:HiddenField ID="HiddenField4" runat="server" Value='<%# Bind("SortNo") %>' />
    <asp:HiddenField ID="HiddenField9" runat="server" Value='<%# Bind("HierarchySortNo") %>' />
    <table>
    <tr style="height:30px">
    <td>
    <span class="label">Context:&nbsp;</span>
    </td>
    <td>
    <asp:Label ID="LabelParent" CssClass="label" runat="server" />
    </td>
    </tr>
    <tr>
    <td>
    <span class="label">Section Type:</span>
    </td>
    <td>
    <asp:Label ID="LabelSectionType" CssClass="label" Text='<%# Eval("SectionType") %>' runat="server" />
    </td>
    </tr>
    <tr>
    <td>
    <span class="label">Section Name:&nbsp;</span>
    </td>
    <td>
    <telerik:RadTextBox ID="RadTextBoxContentName" Width="450px" Runat="server"
    Text='<%# Bind("ContentName") %>' Enabled="false">
    </telerik:RadTextBox>
    </td>
    </tr>
    <tr>
    <td>
    <span class="label">Section Title:&nbsp;</span>
    </td>
    <td>
    <telerik:RadTextBox ID="RadTextBoxContentLabel" Width="450px" Runat="server"
    Text='<%# Bind("ContentLabel") %>' Enabled="false">
    </telerik:RadTextBox>
    </td>
    </tr>
    <tr>
    <td>
    <span class="label">Mandatory:&nbsp;</span>
    </td>
    <td>
    <asp:Label ID="Label3" CssClass="label" Text='<%# Eval("IsMandatoryText") %>' runat="server" />
    </td>
    </tr>
    </table>
    <table style="margin-top:10px">
    </table>
    <table style="margin-top:10px">
    <tr>
    <td>
    <span class="label">Created:&nbsp;</span>
    </td>
    <td>
    <asp:Label ID="Label1" CssClass="label" runat="server"
    Text='<%# Eval("CreatedByUser.DisplayName") + " On " + Eval("CreatedDate") %>' />
    </td>
    <td style="padding-left:30px">
    <span class="label">Last Updated:&nbsp;</span>
    </td>
    <td>
    <asp:Label ID="Label2" CssClass="label" runat="server"
    Text='<%# Eval("LastUpdatedByUser.DisplayName") + " On " + Eval("LastUpdatedDate") %>' />
    </td>
    </tr>
    </table>
    <div style="margin-top:10px">
    <table>
    <tr>
    <td>
    <telerik:RadEditor ID="RadEditor1" runat="server" Content='<%# Bind("Content") %>' Enabled="false"
    StripFormattingOptions="MsWord,Span,Css,ConvertWordLists" Width="625px" ToolsFile="~/RadEditorToolsFile.xml" ImageManager-ViewPaths="~/UserImages">
    <CssFiles>
    <telerik:EditorCssFile Value="~/Styles/radeditor.css" />
    </CssFiles>
    <Tools>
    <telerik:EditorToolGroup>
    <telerik:EditorTool Name="InsertDocumentLink" Text="Insert Within Document Link" />
    </telerik:EditorToolGroup>
    </Tools>
    </telerik:RadEditor>
    </td>
    <td style="padding-left:15px; vertical-align:top">
    <asp:Panel ID="PanelBusinessLineDocumentContent" runat="server">
    <div class="section" style="width:475px">
    <div class="section-header">
    <span class="label">LOB Applicable</span>
    </div>
    <div style="padding:5px">
    <table>
    <tr>
    <td style="padding-top:5px">
    <telerik:RadGrid ID="RadGridBusinessLineDocumentContent" runat="server"
    AutoGenerateColumns="False" GridLines="None" Height="330px" Width="460px">
    <ClientSettings>
    <Scrolling AllowScroll="True" UseStaticHeaders="True" />
    </ClientSettings>
    <MasterTableView DataKeyNames="BusinessLineId">
    <Columns>
    <telerik:GridBoundColumn DataField="BusinessLineId" Visible="false" UniqueName="BusinessLineId" />
    <telerik:GridBoundColumn DataField="BusinessLineName" HeaderText="Business Line" UniqueName="BusinessLineName" />
    <telerik:GridBoundColumn DataField="ApplicableText" HeaderText="Applicable?" UniqueName="ApplicableText">
    <ItemStyle Width="75px" />
    </telerik:GridBoundColumn>
    </Columns>
    <NoRecordsTemplate>
    <i><span style="padding-left:2px">No business lines apply</span></i>
    </NoRecordsTemplate>
    </MasterTableView>
    </telerik:RadGrid>
    </td>
    </tr>
    </table>
    </div>
    </div>
    </asp:Panel>
    </td>
    </tr>
    </table>
    </div>
    <br />
    <telerik:RadButton ID="RadButtonCancel" runat="server" Text="Back" ButtonType="LinkButton"
    CommandName="Cancel" CausesValidation="False" CssClass="std-button" onclick="RadButtonCancel_Click">
    </telerik:RadButton>
    </ItemTemplate>
    </asp:FormView>

    <asp:EntityDataSource ID="DocumentContentDataSource" runat="server"
    ConnectionString="name=CompConEntities" DefaultContainerName="CompConEntities"
    EnableDelete="True" EnableFlattening="False" EnableInsert="True"
    Include="ParentContent.ParentContent.ParentContent,LastUpdatedByUser,CreatedByUser,DocumentVersion,BusinessLineDocumentContents.BusinessLine,ChildContents"
    EnableUpdate="True" EntitySetName="DocumentContents"
    AutoGenerateWhereClause="true"
    oncontextcreating="Generic_ContextCreating"
    onupdating="DocumentContentDataSource_Updating"
    oncontextdisposing="Generic_ContextDisposing"
    oninserting="DocumentContentDataSource_Inserting"
    oninserted="DocumentContentDataSource_Inserted">
    <WhereParameters>
    <asp:QueryStringParameter Name="ContentId" QueryStringField="cid" Type="Int32" />
    </WhereParameters>
    </asp:EntityDataSource>

    <%-- Updated controls are added programmatically in prerender --%>
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    </telerik:RadAjaxManager>

    </asp:Content>

    .CS file

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using CompConData;
    using Telerik.Web.UI;

    public partial class ContentDetailPage : System.Web.UI.Page
    {
    static log4net.ILog _log = log4net.LogManager.GetLogger(typeof(ContentDetailPage));

    CompConEntities _context = null;

    protected bool IsReferrerHierarchy
    {
    get
    {
    object obj = ViewState["IsReferrerHierarchy"];
    if (obj != null)
    return (bool)obj;
    else
    return false;
    }

    set
    {
    ViewState["IsReferrerHierarchy"] = value;
    }
    }

    protected int VersionId
    {
    get
    {
    object obj = ViewState["VersionId"];
    if (obj != null)
    return (int)obj;
    else
    return -1;
    }

    set
    {
    ViewState["VersionId"] = value;
    }
    }

    /// <summary>
    /// When in insert mode & from hierarchy, this will be the content id to restore
    /// </summary>
    protected string InsertCancelContentId
    {
    get
    {
    object obj = ViewState["InsertCancelContentId"];
    if (obj != null)
    return (string)obj;
    else
    return null;
    }

    set
    {
    ViewState["InsertCancelContentId"] = value;
    }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
    if (!SecurityController.IsInAdminRole()) throw new CustomSecurityException();

    _context = new CompConEntities();

    if (!Page.IsPostBack)
    {
    // Check if from hierarchy
    if (Session["FromHierarchy"] != null)
    {
    this.IsReferrerHierarchy = true;
    Session.Remove("FromHierarchy");
    }

    if (Request.QueryString[Constants.KeyContentId] != null)
    {
    this.Master.BreadcrumbLabelText = "You are here: Policy Document > Document Maintenance > Detail";

    // Switch to read only template if version is in progress
    this.SwitchToReadonlyIfShould(Convert.ToInt32(Request.QueryString[Constants.KeyContentId]));
    }
    else
    {
    this.Master.BreadcrumbLabelText = "You are here: Policy Document > Document Maintenance > Detail (New)";

    this.FormView1.ChangeMode(FormViewMode.Insert);
    }
    }
    }

    protected void Page_Unload(object sender, EventArgs e)
    {
    if (_context != null) _context.Dispose();
    }

    private void SwitchToReadonlyIfShould(int contentId)
    {
    var result = _context.DocumentContents.Include("DocumentVersion")
    .Where(c => c.ContentId == contentId);

    if (result.Count() > 0)
    {
    if (result.First().DocumentVersion.VersionStatusCode !=
    CompConCommon.Constants.STATUS_IN_PROGRESS)
    {
    this.FormView1.ChangeMode(FormViewMode.ReadOnly);
    }
    }
    }

    private void InitializeContentComboBoxes()
    {
    // Populate chapter level content
    List<DocumentContent> documentContentList = _context.DocumentContents
    .Where(c => c.DocumentVersion.VersionStatusCode == CompConCommon.Constants.STATUS_IN_PROGRESS)
    .Where(c => c.Level == 1)
    .OrderBy(c => c.SortNo).ToList();

    RadComboBox radComboBox = (RadComboBox)this.FormView1.FindControl("RadComboBoxChapter");

    radComboBox.DataSource = documentContentList;
    radComboBox.DataBind();
    }

    private void InitializeContentComboBoxesFromContext(string contextAsCommaDelimitedStr)
    {
    // Get the context into array
    char[] seps = { ',' };
    string[] contextStrArr = contextAsCommaDelimitedStr.Split(seps);
    this.InsertCancelContentId = contextStrArr[contextStrArr.Length - 1];

    // Populate chapter level content
    List<DocumentContent> documentContentList = _context.DocumentContents
    .Where(c => c.DocumentVersion.VersionStatusCode == CompConCommon.Constants.STATUS_IN_PROGRESS)
    .Where(c => c.Level == 1)
    .OrderBy(c => c.SortNo).ToList();

    RadComboBox radComboBoxChapter = (RadComboBox)this.FormView1.FindControl("RadComboBoxChapter");
    radComboBoxChapter.DataSource = documentContentList;
    radComboBoxChapter.DataBind();

    if (radComboBoxChapter.Items.Any(i => i.Value == contextStrArr[0]))
    {
    radComboBoxChapter.SelectedValue = contextStrArr[0];
    }

    if (radComboBoxChapter.SelectedIndex > 0) // First value is empty
    {
    // Populate header level content
    int chapterContentId = Convert.ToInt32(radComboBoxChapter.SelectedValue);

    List<DocumentContent> headingContentList = _context.DocumentContents
    .Where(c => c.ParentContentId == chapterContentId)
    .OrderBy(c => c.SortNo).ToList();

    RadComboBox radComboBoxHeading = (RadComboBox)this.FormView1.FindControl("RadComboBoxHeading");
    radComboBoxHeading.DataSource = headingContentList;
    radComboBoxHeading.DataBind();

    if (contextStrArr.Length > 1)
    {
    if (radComboBoxHeading.Items.Any(i => i.Value == contextStrArr[1]))
    {
    radComboBoxHeading.SelectedValue = contextStrArr[1];
    }
    }
    }
    }

    protected void RadButtonSave_Click(object sender, EventArgs e)
    {

    }

    protected void RadButtonCancel_Click(object sender, EventArgs e)
    {
    if (this.IsReferrerHierarchy && this.FormView1.CurrentMode == FormViewMode.Edit)
    {
    Session[Constants.KeyContentId] = this.FormView1.DataKey["ContentId"];
    Response.Redirect(string.Format("~/Content/ContentHierarchy.aspx?{0}={1}",
    Constants.KeyVersionId,
    this.VersionId));
    }
    else if (this.IsReferrerHierarchy && this.FormView1.CurrentMode == FormViewMode.Insert)
    {
    Session[Constants.KeyContentId] = this.InsertCancelContentId;
    Response.Redirect(string.Format("~/Content/ContentHierarchy.aspx?{0}={1}",
    Constants.KeyVersionId,
    this.VersionId));
    }
    else
    {
    StateRestorer stateRestorer = new StateRestorer();
    stateRestorer.MarkShouldRestore();

    Response.Redirect("~/Content/ContentList.aspx");
    }
    }

    protected void RadComboBoxChapter_SelectedIndexChanged(object sender, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
    {
    if (e.OldValue == e.Value) return;

    // Get new data for heading
    int parentContentId = Convert.ToInt32(e.Value);

    List<DocumentContent> contentList = _context.DocumentContents
    .Where(c => c.DocumentVersion.VersionStatusCode == CompConCommon.Constants.STATUS_IN_PROGRESS)
    .Where(c => c.ParentContentId == parentContentId)
    .OrderBy(c => c.SortNo).ToList();

    // Rebind heading
    RadComboBox radComboBox = (RadComboBox)this.FormView1.FindControl("RadComboBoxHeading");
    this.ClearAndRebind(radComboBox, contentList);
    }

    protected void Generic_ContextCreating(object sender, EntityDataSourceContextCreatingEventArgs e)
    {
    e.Context = _context;
    }

    protected void Generic_ContextDisposing(object sender, EntityDataSourceContextDisposingEventArgs e)
    {
    e.Cancel = true;
    }

    protected void FormView1_ItemDeleted(object sender, FormViewDeletedEventArgs e)
    {
    if (e.Exception == null)
    {
    if (this.IsReferrerHierarchy)
    {
    Response.Redirect(string.Format("~/Content/ContentHierarchy.aspx?{0}={1}",
    Constants.KeyVersionId,
    this.VersionId));
    }
    else
    {
    Response.Redirect("~/Content/ContentList.aspx");
    }
    }
    }

    protected void FormView1_PreRender(object sender, EventArgs e)
    {
    if (this.FormView1.CurrentMode == FormViewMode.Edit)
    {
    RadButton radButtonSave = this.FormView1.FindControl("RadButtonSave") as RadButton;
    this.RadAjaxManager1.AjaxSettings.AddAjaxSetting(radButtonSave, this.FormView1, this.RadAjaxLoadingPanel1);
    }
    }

    protected void FormView1_DataBound(object sender, EventArgs e)
    {
    if (this.FormView1.CurrentMode == FormViewMode.Edit)
    {
    DocumentContent documentContent = (DocumentContent)this.FormView1.DataItem;

    // Set version info
    this.VersionId = documentContent.VersionId;

    // Sets the parent label
    this.SetParentLabel(documentContent);

    if (documentContent.IsMandatory)
    {
    Panel panelBusinessLineDocumentContent =
    (Panel)this.FormView1.FindControl("PanelBusinessLineDocumentContent");

    panelBusinessLineDocumentContent.Visible = false;
    }
    else
    {
    // Bind the business line grid
    this.BindBusinessLineDocumentContentItems(documentContent);
    }

    // Disable delete if any child objects exist
    if (documentContent.ChildContents != null && documentContent.ChildContents.Count() > 0)
    {
    RadButton radButton = (RadButton)this.FormView1.FindControl("RadButtonDelete");
    radButton.Enabled = false;
    }
    }
    else if (this.FormView1.CurrentMode == FormViewMode.Insert)
    {
    // Initialize content combo boxes. May have values passed from hierarchy
    if (Session["ContentIdHierarchyContext"] != null)
    {
    this.InitializeContentComboBoxesFromContext(Session["ContentIdHierarchyContext"].ToString());
    Session.Remove("ContentIdHierarchyContext");
    }
    else
    {
    this.InitializeContentComboBoxes();
    }

    // Set version info
    var version = _context.DocumentVersions
    .Where(v => v.VersionStatusCode == CompConCommon.Constants.STATUS_IN_PROGRESS)
    .OrderByDescending(v => v.StartDate);

    if (version == null || version.Count() == 0)
    throw new ApplicationException("Must have version in progress for insert");

    this.VersionId = version.First().VersionId;

    RadTextBox radTextBox = (RadTextBox)this.FormView1.FindControl("RadTextBoxVersion");
    radTextBox.Text = version.First().VersionName;
    }
    else
    {
    DocumentContent documentContent = (DocumentContent)this.FormView1.DataItem;

    // Set version info
    this.VersionId = documentContent.VersionId;

    // Sets the parent label
    this.SetParentLabel(documentContent);

    if (documentContent.IsMandatory)
    {
    Panel panelBusinessLineDocumentContent =
    (Panel)this.FormView1.FindControl("PanelBusinessLineDocumentContent");

    panelBusinessLineDocumentContent.Visible = false;
    }
    else
    {
    // Bind the business line grid
    this.BindBusinessLineDocumentContentItems(documentContent);
    }
    }
    }

    /// <summary>
    /// Sets the parent information in the form for edit.
    /// </summary>
    private void SetParentLabel(DocumentContent documentContent)
    {
    List<string> parentList = new List<string>();

    while (documentContent.ParentContent != null)
    {
    parentList.Add(documentContent.ParentContent.ContentLabel);
    documentContent = documentContent.ParentContent;
    }

    parentList.Reverse();

    Label labelParent = (Label)this.FormView1.FindControl("LabelParent");
    labelParent.Text = string.Join(" > ", parentList);
    }

    protected void DocumentContentDataSource_Inserting(object sender, EntityDataSourceChangingEventArgs e)
    {
    DocumentContent content = (DocumentContent)e.Entity;

    // Set user values
    content.LastUpdatedBy = SecurityController.GetCurrentUserId();
    content.CreatedBy = SecurityController.GetCurrentUserId();

    // Set the version
    content.VersionId = this.VersionId;

    // Set the parent
    RadComboBox radComboBox = (RadComboBox)this.FormView1.FindControl("RadComboBoxHeading");

    if (radComboBox.SelectedIndex > 0)
    {
    content.ParentContentId = Convert.ToInt32(radComboBox.SelectedValue);
    content.Level = 3;
    }
    else
    {
    radComboBox = (RadComboBox)this.FormView1.FindControl("RadComboBoxChapter");

    if (radComboBox.SelectedIndex > 0)
    {
    content.ParentContentId = Convert.ToInt32(radComboBox.SelectedValue);
    content.Level = 2;
    }
    else
    {
    var root = _context.DocumentContents.Where(c => c.Level == 0)
    .Where(c => c.VersionId == this.VersionId);

    content.ParentContentId = root.First().ContentId;
    content.Level = 1;
    }
    }
    }

    protected void DocumentContentDataSource_Inserted(object sender, EntityDataSourceChangedEventArgs e)
    {
    if (e.Exception == null)
    {
    DocumentContent item = (DocumentContent)e.Entity;

    if (this.IsReferrerHierarchy) Session["FromHierarchy"] = true;

    Response.Redirect(string.Format("~/Content/ContentDetail.aspx?{0}={1}",
    Constants.KeyContentId,
    item.ContentId));
    }
    }

    protected void DocumentContentDataSource_Updating(object sender, EntityDataSourceChangingEventArgs e)
    {
    DocumentContent content = (DocumentContent)e.Entity;

    //This code need to be deletee
    //if (!content.ContentChangedInd)
    //{
    // RadWindowManager1.RadConfirm("Server radconfirm: Are you sure?", "confirmCallBackFn", 330, 180, null, "Server RadConfirm");
    //}
    content.LastUpdatedBy = SecurityController.GetCurrentUserId();

    this.MarkBusinessLineDocumentContentItemsForSave(content.IsMandatory);
    }

    private void ClearAndRebind(RadComboBox radComboBox, List<DocumentContent> contentList)
    {
    this.RemoveItemsExceptFirst(radComboBox);

    radComboBox.DataSource = contentList;
    radComboBox.DataBind();
    }

    private void RemoveItemsExceptFirst(RadComboBox radComboBox)
    {
    RadComboBoxItem item = radComboBox.Items[0];
    radComboBox.Items.Clear();
    radComboBox.Items.Insert(0, item);
    }

    // Temp method for checkbox check while content is updated
    private void Update_Click(object sender, EventArgs e)
    {

    }

    #region Business Line Document Content grid methods

    /// <summary>
    /// Data item for the business line document content grid.
    /// </summary>
    class BusinessLineGridItem
    {
    public int BusinessLineId { get; set; }

    public string BusinessLineName { get; set; }

    public string ApplicableText { get; set; }
    }

    protected void LinkButtonRemoveAllBusinessLines_Click(object sender, EventArgs e)
    {
    // New list to bind
    List<BusinessLineGridItem> businessLineGridItemList = new List<BusinessLineGridItem>();

    // Rebind the grid
    this.BindBusinessLineDocumentContentGrid(businessLineGridItemList);

    // Rebind the combo box
    this.BindBusinessLineDocumentContentComboBoxArea(
    businessLineGridItemList.Select(b => b.BusinessLineId).ToList());
    }

    protected void LinkButtonRemoveBusinessLine_Click(object sender, EventArgs e)
    {
    // Build the new grid item list
    RadGrid radGrid = (RadGrid)this.FormView1.FindControl("RadGridBusinessLineDocumentContent");
    List<BusinessLineGridItem> businessLineGridItemList = this.GetBusinessLineGridItems(radGrid);

    // Get the business line id removed
    LinkButton linkButton = sender as LinkButton;
    int businessLineId = Convert.ToInt32(linkButton.CommandArgument);

    // Get new list without that one item
    businessLineGridItemList = businessLineGridItemList.Where(b => b.BusinessLineId != businessLineId).ToList();

    // Rebind the grid
    this.BindBusinessLineDocumentContentGrid(businessLineGridItemList);

    // Rebind the combo box
    this.BindBusinessLineDocumentContentComboBoxArea(
    businessLineGridItemList.Select(b => b.BusinessLineId).ToList());
    }

    protected void RadButtonAddAllBusinessLine_Click(object sender, EventArgs e)
    {
    RadGrid radGrid = (RadGrid)this.FormView1.FindControl("RadGridBusinessLineDocumentContent");
    List<BusinessLineGridItem> businessLineGridItemList = this.GetBusinessLineGridItems(radGrid);
    List<int> businessLineGridItemIdList = businessLineGridItemList.Select(b => b.BusinessLineId).ToList();

    List<BusinessLine> businessLineList = StaticDataCacheManager.GetBusinessLines();
    foreach (BusinessLine businessLine in businessLineList)
    {
    if (!businessLineGridItemIdList.Contains(businessLine.BusinessLineId))
    {
    businessLineGridItemList.Add(new BusinessLineGridItem()
    {
    BusinessLineId = businessLine.BusinessLineId,
    BusinessLineName = businessLine.BusinessLineName,
    ApplicableText = "Yes",
    });
    }
    }

    // Rebind the grid
    this.BindBusinessLineDocumentContentGrid(businessLineGridItemList);

    // Rebind the combo box
    this.BindBusinessLineDocumentContentComboBoxArea(businessLineGridItemList.Select(b => b.BusinessLineId).ToList());
    }

    protected void RadButtonAddBusinessLine_Click(object sender, EventArgs e)
    {
    // Get the selected business line the user wants to add
    RadComboBox radComboBox = (RadComboBox)this.FormView1.FindControl("RadComboBoxBusinessLine");
    int businessLineId = Convert.ToInt32(radComboBox.SelectedValue);
    string businessLineName = radComboBox.Text;

    // Create the new grid item & add to the existing grid item list
    BusinessLineGridItem newItem = new BusinessLineGridItem();
    newItem.BusinessLineId = businessLineId;
    newItem.BusinessLineName = businessLineName;
    newItem.ApplicableText = "Yes";

    RadGrid radGrid = (RadGrid)this.FormView1.FindControl("RadGridBusinessLineDocumentContent");
    List<BusinessLineGridItem> businessLineGridItemList = this.GetBusinessLineGridItems(radGrid);
    businessLineGridItemList.Add(newItem);

    // Rebind the grid
    this.BindBusinessLineDocumentContentGrid(businessLineGridItemList);

    // Rebind the combo box
    this.BindBusinessLineDocumentContentComboBoxArea(businessLineGridItemList.Select(b => b.BusinessLineId).ToList());
    }

    private void MarkBusinessLineDocumentContentItemsForSave(bool newIsMandatoryValue)
    {
    int contentId = Convert.ToInt32(this.FormView1.DataKey["ContentId"]);

    DocumentContent existingDocumentContent = _context.DocumentContents.Include("BusinessLineDocumentContents")
    .Where(c => c.ContentId == contentId).First();

    // Change from not mandatory -> mandatory
    if (!existingDocumentContent.IsMandatory && newIsMandatoryValue)
    {
    // Mark all as mandatory
    this.AllShouldBeThisApplicableCode(existingDocumentContent, "M");
    }
    // Change from mandatory -> not mandatory
    else if (existingDocumentContent.IsMandatory && !newIsMandatoryValue)
    {
    // Mark all as applicable
    this.AllShouldBeThisApplicableCode(existingDocumentContent, "Y");
    }
    // Content stays not mandatory
    else if (!existingDocumentContent.IsMandatory && !newIsMandatoryValue)
    {
    RadGrid radGrid = (RadGrid)this.FormView1.FindControl("RadGridBusinessLineDocumentContent");
    List<BusinessLineGridItem> newList = this.GetBusinessLineGridItems(radGrid);

    this.MarkBusinessLineDocumentContentItemsForSave(existingDocumentContent,
    newList.Select(b => b.BusinessLineId).ToList());
    }
    }

    private void MarkBusinessLineDocumentContentItemsForSave(DocumentContent content, List<int> newBusinessIdList)
    {
    // Delete those that are currently associated but not in new list.
    List<BusinessLineDocumentContent> existingBLDCList =
    content.BusinessLineDocumentContents.ToList();

    for (int i = 0; i < existingBLDCList.Count; i++)
    {
    BusinessLineDocumentContent item = existingBLDCList[i];

    if (!newBusinessIdList.Contains(item.BusinessLineId))
    {
    _context.DeleteObject(item);
    }
    }

    // Add those that are not associated but in new list
    List<int> existingBLDCIntList =
    existingBLDCList.Select(bldc => bldc.BusinessLineId).ToList();

    foreach (int newBusinessLineId in newBusinessIdList)
    {
    if (!existingBLDCIntList.Contains(newBusinessLineId))
    {
    this.AddNewBusinessLineDocumentToContext(newBusinessLineId, content.ContentId, "Y");
    }
    }
    }

    private void AllShouldBeThisApplicableCode(DocumentContent content, string applicableCode)
    {
    // Mark all currently associated to the given applicable code
    foreach (var item in content.BusinessLineDocumentContents)
    {
    if (item.ApplicableCode != applicableCode) item.ApplicableCode = applicableCode;
    }

    // Add any business lines that are not associated by getting those items in the all business line
    // ids list that are not in the current business line id list
    List<int> allBusinessLineIds =
    StaticDataCacheManager.GetBusinessLines().Select(b => b.BusinessLineId).ToList();

    List<int> unassociatedBusinessLineIds =
    allBusinessLineIds.Except(content.BusinessLineDocumentContents.Select(bldv => bldv.BusinessLineId).ToList()).ToList();

    foreach (int unassociatedBusinessLineId in unassociatedBusinessLineIds)
    this.AddNewBusinessLineDocumentToContext(unassociatedBusinessLineId, content.ContentId, applicableCode);

    }

    private List<BusinessLineGridItem> GetBusinessLineGridItems(RadGrid radGrid)
    {
    List<BusinessLineGridItem> list = new List<BusinessLineGridItem>();

    foreach (var item in radGrid.MasterTableView.Items)
    {
    GridDataItem gridDataItem = item as GridDataItem;

    BusinessLineGridItem businessLineGridItem = new BusinessLineGridItem();
    businessLineGridItem.BusinessLineId = Convert.ToInt32(gridDataItem["BusinessLineId"].Text);
    businessLineGridItem.BusinessLineName = gridDataItem["BusinessLineName"].Text;
    businessLineGridItem.ApplicableText = gridDataItem["ApplicableText"].Text;

    list.Add(businessLineGridItem);
    }

    return list;
    }

    private void AddNewBusinessLineDocumentToContext(int businessLineId, int contentId, string applicableCode)
    {
    BusinessLineDocumentContent newBusinessLineDocumentContent = new BusinessLineDocumentContent();

    newBusinessLineDocumentContent.BusinessLineId = businessLineId;
    newBusinessLineDocumentContent.ContentId = contentId;
    newBusinessLineDocumentContent.ApplicableCode = applicableCode;
    newBusinessLineDocumentContent.LastUpdatedBy = SecurityController.GetCurrentUserId();

    _context.AddToBusinessLineDocumentContents(newBusinessLineDocumentContent);
    }

    private void BindBusinessLineDocumentContentItems(DocumentContent documentContent)
    {
    // Get all applicable business lines
    List<BusinessLineDocumentContent> applicableBLDCList = documentContent.BusinessLineDocumentContents.ToList();

    // Bind the grid
    List<BusinessLineGridItem> businessLineGridItemList =
    (from bldc in applicableBLDCList
    select
    new BusinessLineGridItem {
    BusinessLineId = bldc.BusinessLineId,
    BusinessLineName = bldc.BusinessLine.BusinessLineName,
    ApplicableText = bldc.ApplicableCodeDesc}).ToList();

    this.BindBusinessLineDocumentContentGrid(businessLineGridItemList);

    if (this.FormView1.CurrentMode == FormViewMode.Edit)
    {
    // Bind the combo box
    this.BindBusinessLineDocumentContentComboBoxArea(
    applicableBLDCList.Select(bldc => bldc.BusinessLineId).ToList());
    }
    }

    private void BindBusinessLineDocumentContentGrid(List<BusinessLineGridItem> businessLineGridItemList)
    {
    // Bind to the grid
    RadGrid radGrid = (RadGrid)this.FormView1.FindControl("RadGridBusinessLineDocumentContent");
    radGrid.DataSource = businessLineGridItemList.OrderBy(b => b.BusinessLineName).ToList();
    radGrid.DataBind();
    }

    private void BindBusinessLineDocumentContentComboBoxArea(List<int> applicableBLDCIdList)
    {
    List<BusinessLine> businessLineList = StaticDataCacheManager.GetBusinessLines();

    List<BusinessLine> bindBusinessLineList = new List<BusinessLine>();

    foreach (BusinessLine businessLine in businessLineList)
    {
    if (!applicableBLDCIdList.Contains(businessLine.BusinessLineId))
    {
    bindBusinessLineList.Add(businessLine);
    }
    }

    // combobox
    RadComboBox radComboBox = (RadComboBox)this.FormView1.FindControl("RadComboBoxBusinessLine");
    radComboBox.DataSource = bindBusinessLineList.OrderBy(b => b.BusinessLineName).ToList();
    radComboBox.DataBind();
    radComboBox.Enabled = (bindBusinessLineList.Count() > 0);

    // add business line button
    RadButton radButtonAdd = (RadButton)this.FormView1.FindControl("RadButtonAddBusinessLine");
    radButtonAdd.Enabled = (bindBusinessLineList.Count() > 0);

    // add all business line button
    RadButton radButtonAddAll = (RadButton)this.FormView1.FindControl("RadButtonAddAllBusinessLine");
    radButtonAddAll.Enabled = (bindBusinessLineList.Count() > 0);
    }

    #endregion
    }

    Thanks,
    S

  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 04 Feb 2014 in reply to Shyam Link to this post

    Hi Shyam,

    Please have a look into the following code snippet to achieve your scenario.

    ASPX:
    <telerik:RadWindowManager ID="RadWindowManager1" runat="server">
    </telerik:RadWindowManager>
    <telerik:RadButton ID="RadButton1" ToggleType="CheckBox" runat="server" Text="Checked"
        ButtonType="ToggleButton">
    </telerik:RadButton>
    <telerik:RadButton ID="RadButton2" runat="server" Text="Save" AutoPostBack="false"
        OnClientClicking="OnClientClicking1">
    </telerik:RadButton>

    JavaScript:
    <script type="text/javascript">
        Telerik.Web.UI.RadWindowUtils.Localization =
        {
            "OK": "Yes",
            "Cancel": "No"
        };
        function OnClientClicking1(sender, args) {
            var checkbox = $find("<%=RadButton1.ClientID %>");
            if (checkbox.get_checked() == false) {
                radconfirm('Check the Check box and try', confirmCallBackFn, 330, 180, null, 'Client RadConfirm', null);
            }
        }
        function confirmCallBackFn(arg) {
            if (arg == true) {
                var checkbox = $find("<%=RadButton1.ClientID %>");
                checkbox.set_checked(true);
            }
        }
    </script>

    Thanks,
    Shinu.
  3. Shyam
    Shyam avatar
    5 posts
    Member since:
    Feb 2014

    Posted 05 Feb 2014 in reply to Shinu Link to this post

    Hi Shinu,

    Thanks for your reply. But in OnClientClicking1 function at line  if (checkbox.get_checked() == false) {, i'm getting below error.

    Error: Object doesn't support property or method 'get_checked'

    And about function confirmCallBackFn(arg), where do i need to call this? Is it on checkbox control? If it is, on which event i need to call it. Please help.

    Thanks,
    S
  4. Shyam
    Shyam avatar
    5 posts
    Member since:
    Feb 2014

    Posted 05 Feb 2014 in reply to Shyam Link to this post

    Sorry Shinu, I know where is confirmCallBackFn. Please just reply to the Error: Object doesn't support property or method 'get_checked'

    Thanks,
    S
  5. Shyam
    Shyam avatar
    5 posts
    Member since:
    Feb 2014

    Posted 05 Feb 2014 in reply to Shinu Link to this post

    Hi Shinu,

    I'm able to fix the JavaScript error. I modified code below.

    function OnClientSave(sender, args) {
    var checkbox = '<%=FormView1.FindControl("RadButtonContentChanged").ClientID%>';
    if (sender.get_checked() == false) {
    radconfirm('Is this the Content change?', confirmCallBackFn, 330, 180, null, 'Content Change', null);
    }
    }

    But i still see the error in "confirmCallBackFn".  Error: Object doesn't support property or method 'get_checked'.

    And one more thing, when i click on Save button, page is getting postbacked. How to prevent this? I just would like to postback the page after i click on Yes/No button from Confirmation Window not from the save button.

    Please help. It is very urgent.

    Thanks,
    S
  6. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 05 Feb 2014 in reply to Shyam Link to this post

    Hi Shyam,

    Please have a look into the following modification that I did in your code and which works fine at my end. To prevent the postback from Save Button try to set the AutoPostBack to false.

    JavaScript:
    <script type="text/javascript">
        Telerik.Web.UI.RadWindowUtils.Localization =
        {
            "OK": "Yes",
            "Cancel": "No"
        };
        function OnClientSave(sender, args) {
            var checkbox = document.getElementById('<%=FormView1.FindControl("RadButtonContentChanged").ClientID%>');
            if (checkbox.control.get_checked() == false)
                radconfirm('Is this the Content change?', confirmCallBackFn, 330, 180, null, 'Content Change', null);
        }
        function confirmCallBackFn(arg) {
            if (arg == true) {
                var checkbox = document.getElementById('<%=FormView1.FindControl("RadButtonContentChanged").ClientID%>');
                checkbox.control.set_checked(true);
            }
        }
    </script>

    Let me know if you have any concern.
    Thanks,
    Shinu.
  7. Shyam
    Shyam avatar
    5 posts
    Member since:
    Feb 2014

    Posted 11 Feb 2014 in reply to Shinu Link to this post

    Thanks Shinu. It worked perfectly.

    Thanks again,
    S
Back to Top