Tabstrip in usercontrol not working

1 posts, 0 answers
  1. Kaushik Saha
    Kaushik Saha avatar
    1 posts
    Member since:
    Apr 2006

    Posted 24 Apr 2012 Link to this post

    Hello,

           I am running into a problem with a RadTabStrip inside a user control. Here is the problem :

           I have a RadTabStrip inside a user control which has a RadMultiPage associated with it.The RadTabStrip has multiple tabs. There is a RadMultiPage associated with the RadTabStrip.

          The user control is called in an aspx page. The aspx page has RadAjaxManager.   

           There is a RadGrid in the aspx page. When row selected event of the RadGrid is fired then the user control is loaded dynamically in a Panel.

           The user control loads fine in the rowselected event of the RadGrid. But when the Tabs of the RadTabStrip is changed it does not load the correcponding PageView of the Radmultipage does not load.

          Can anyone help me on this here is the code :

        Code for Aspx Page :

         
    <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
                        <script type="text/javascript">
                            function onRequestStart(sender, args) {
                                if (args.get_eventTarget().indexOf("ExportToExcelButton") >= 0 ||
                        args.get_eventTarget().indexOf("ExportToWordButton") >= 0 ||
                        args.get_eventTarget().indexOf("ExportToPdfButton") >= 0 ||
                        args.get_eventTarget().indexOf("ExportToCsvButton") >= 0) {
                                    args.set_enableAjax(false);
                                }
                            }
                        </script>

                        <style>
                        .rtbInner{text-align:center;}
                        </style>
    </telerik:RadCodeBlock>
    </asp:Content>

    <asp:Content ID="Content3" ContentPlaceHolderID="main" runat="Server">
    <telerik:RadCodeBlock ID="RadCodeBlock2" runat="server">
    <script src="../../js/scroll-startstop.events.jquery.js" type="text/javascript"></script>
    </telerik:RadCodeBlock>
    <style>
    .loadingpanel{background: no-repeat center;}
    </style>
    <telerik:RadCodeBlock ID="RadCodeBlock3" runat="server">
    <script type="text/javascript">
        var startDate = '';
        var endDate = '';

        function OnStartDateSelected(sender, e) {
            if (e.get_newDate() != null) {
                startDate = e.get_newDate().toDateString();
                //startDate = e.get_dateFormatInfo().FormatDate(e.get_selectedDate, e.get_displayDateFormat());
                //alert(startDate);
            }
            else {
                startDate = '';
            }
        }

        function OnEndDateSelected(sender, e) {
            if (e.get_newDate() != null) {
                endDate = e.get_newDate().toDateString();
            }
            else {
                endDate = '';
            }
        }


    var onlyNew = '';


    $(function() {

        var printUrl = 'Print.aspx?aid=<%= _useAgentId %>&cmp=<asp:literal runat="server" id="_campaignId" />';

        $("#dialog-form").dialog({
            autoOpen: false,
            height: 250,
            width: 750,
            modal: true,
            buttons: {
                "Print": function() {

                    var perpageValue = '1';
                    var markreadValue = 'no';
                    if ($('#perpage').is(":checked")) { perpageValue = '3'; }
                    if ($('#markread').is(":checked")) { markreadValue = 'yes'; }
         
                    var windowPath = printUrl + onlyNew + '&pp=' + perpageValue + '&mr=' + markreadValue + '&sd=' + startDate + '&ed=' + endDate;
                    window.open(windowPath, 'null', 'height=700,width=900,status=yes,toolbar=yes,menubar=yes,location=yes,scrollbars=yes');
                    //window.open();
                    $(this).dialog("close");
                },
                Cancel: function() {
                    $(this).dialog("close");
                }
            },
            close: function() {
            }
        });
    });


                function clientButtonClicked(sender, args)
                {
                    if (args.get_item().get_text() == 'Print Unread') { onlyNew = '&new=true' } else { onlyNew = '&new=false' };
                    if (args.get_item().get_text() == 'Print Date Range') { $("#printRange").css("display", "inline") } else {$("#printRange").css("display", "none") } ;
                    $("#dialog-form").dialog("open");
                }

    </script>
    </telerik:RadCodeBlock>

    <a name="card"></a>

    <div id="dialog-form" title="Print" style="display:none;" >
        
        <p><b>Mark leads as Read?</b>
                        <input type="checkbox" id="markread" />Yes! Mark these leads as read when I click "Print".
                        <div style="margin-left:200px;font-size:9px;">
                        Checking 'Yes' will mark all printed leads as 'Read' <br>so they will not show up as 'New' in LeadTracker.
                        </div>
        </p>
        <div id="printRange" style="display:none;">
            <b>Start Date:</b>
            
            <telerik:RadDatePicker runat="server" ID="_printStart" >
                <ClientEvents OnDateSelected="OnStartDateSelected" />
            </telerik:RadDatePicker><br />
            <b>End Date:</b>
            <telerik:RadDatePicker runat="server" ID="_printEnd" >
                    <ClientEvents OnDateSelected="OnEndDateSelected" />
            </telerik:RadDatePicker>

        </div>
    </div>

    <div id="print-help-form" title="Print Help" style="display:none;" >
        <p>This is the help text.</p>
    </div>

        <div class="pageheading"><asp:Literal runat=server ID="_pageheading">New Leads</asp:Literal></div>
        <div class="pagesubheading"><asp:Literal runat=server ID="_pagesubheading">List of all new leads you have received. <br /><b>To find your Viewed Leads, please <a href="Campaigns.aspx" style="text-decoration:underline;">Select a Campaign</a>.</b></asp:Literal></div>

     
        <asp:Panel runat="server" ID="_titlePanel" CssClass="titlePanel"></asp:Panel>

                               
        <telerik:RadSplitter runat="Server" ID="RadSplitter1" Width="100%" BorderSize="0"
            BorderStyle="None" PanesBorderSize="0"  Orientation="Horizontal"
            VisibleDuringInit="false">
            <telerik:RadPane runat="server" ID="contentPane" Scrolling="none" height="300px">
                <telerik:RadSplitter runat="server" ID="RadSplitter2" BorderStyle="None" PanesBorderSize="0">

                    <telerik:RadPane runat="Server" ID="rightPane" CssClass="right-pane" Scrolling="None">
                        <telerik:RadSplitter runat="server" ID="RadSplitter4" Width="100%" BorderSize="0"
                            BorderStyle="None" PanesBorderSize="0" Height="100%" Orientation="Horizontal">
                            <telerik:RadPane runat="server" ID="RadPane2" >
                            
                                        <telerik:RadToolBar runat="server" ID="RadToolBar1" CssClass="inbox-search-toolbar"
                                         Width="100%" OnClientButtonClicked="clientButtonClicked"
                                            EnableViewState="false">
    <%--                                        <Items>
                                                    <telerik:RadToolBarDropDown ImageUrl="~/Images/print.gif">
                                                        <Buttons>
                                                            <telerik:RadToolBarButton Text="Print New" />
                                                            <telerik:RadToolBarButton Text="Print All" />
                                                        </Buttons>
                                                    </telerik:RadToolBarDropDown>
                                                </Items>
    --%>                                    </telerik:RadToolBar>
                                
                                
                                <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
                                    <AjaxSettings>
                                        <telerik:AjaxSetting AjaxControlID="RadGrid1">
                                            <UpdatedControls>
                                                <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />
                                            </UpdatedControls>
                                        </telerik:AjaxSetting>
                                        <telerik:AjaxSetting AjaxControlID="leadPanel">
                                            <UpdatedControls>
                                                <telerik:AjaxUpdatedControl ControlID="leadPanel" LoadingPanelID="RadAjaxLoadingPanel1" />
                                            </UpdatedControls>
                                        </telerik:AjaxSetting>
                                    </AjaxSettings>
                                </telerik:RadAjaxManager>
                                <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" Skin="Default" InitialDelayTime="0"
            MinDisplayTime="1000" EnableSkinTransparency="true" runat="server"/>
                                

                                <telerik:RadGrid height="267px" runat="server" ID="RadGrid1" AutoGenerateColumns="false" OnNeedDataSource="RadGrid1_NeedDataSource"
                                
                                AllowSorting="True"
                                    OnExcelMLExportStylesCreated="RadGrid1_ExcelMLExportStylesCreated"
                                    OnExcelMLExportRowCreated="RadGrid1_ExcelMLExportRowCreated"
                                    OnItemCommand="RadGrid1_ItemCommand"  
                                    GridLines="None"  BorderWidth="0" Style="outline: none" HeaderStyle-Font-Underline="true" GroupingEnabled="false"
                                    ShowGroupPanel="false" OnSelectedIndexChanged="GridRowSelected">
                                    <ClientSettings Scrolling-AllowScroll="True" Scrolling-UseStaticHeaders="true" Selecting-AllowRowSelect="true"
                                         AllowDragToGroup="true" EnablePostBackOnRowClick="true" EnableRowHoverStyle="true">
                                    </ClientSettings>
                                    <MasterTableView TableLayout="Fixed" DataKeyNames="CampaignResponseId" CommandItemDisplay="Top"
                                        AdditionalDataFieldNames="Date">
                                        <%--<NoRecordsTemplate >     
                                         <asp:Label ID="Label2" runat="server" Text="Write your message here"></asp:Label>       
                                        </NoRecordsTemplate>--%>    

                                        <CommandItemSettings ShowExportToPdfButton="true" ShowExportToExcelButton="true" ShowExportToCsvButton="true" ShowAddNewRecordButton="false" />
                                        <Columns>
                                            <telerik:GridTemplateColumn UniqueName="ReadIcon" HeaderText="" >
                                                <HeaderStyle Width="10px" />
                                                <ItemTemplate>
                                                    <asp:Image ID="Image1" ImageUrl='<%# Eval("WasRead", "~/images/{0}.png") %>' runat="server" />
                                                </ItemTemplate>
                                            </telerik:GridTemplateColumn>                        
                                           <telerik:GridTemplateColumn UniqueName="TemplateColumn" HeaderStyle-Width="15px">
                                                <HeaderTemplate>
                                                      <asp:Panel ID="PanelHeader" runat="server">
                                                        <asp:CheckBox ID="CheckBoxHeader"  OnCheckedChanged="HeaderCheckedChanged" runat="server" AutoPostBack="true"  />
                                                    </asp:Panel>
                                                </HeaderTemplate>
                                                <ItemTemplate>
                                                    <asp:Panel ID="Panel1" runat="server">
                                                        <asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="true"  />
                                                    </asp:Panel>
                                                </ItemTemplate>
                                           </telerik:GridTemplateColumn>
                                            
                                            <telerik:GridBoundColumn SortExpression="FirstName"  AllowFiltering="true" DataField="FirstName" HeaderText="First Name" HeaderStyle-Width="40px" />
                                            <telerik:GridBoundColumn SortExpression="LastName"  AllowFiltering="true" DataField="LastName" HeaderText="Last Name" HeaderStyle-Width="40px" />
                                            
                                            <telerik:GridBoundColumn AllowFiltering="true" DataField="Address1" HeaderText="Address" HeaderStyle-Width="80px"></telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn AllowFiltering="true" DataField="City" HeaderText="City" HeaderStyle-Width="60px"></telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn AllowFiltering="true" DataField="State" HeaderText="State" HeaderStyle-Width="20px"></telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn AllowFiltering="true" DataField="Zip" HeaderText="Zip" HeaderStyle-Width="40px"></telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn AllowFiltering="true" DataField="DateAdded" HeaderText="Received" HeaderStyle-Width="40px" DataFormatString="{0:MM/dd/yyyy}">                                                     
                                            </telerik:GridBoundColumn>
                                            
                                            <telerik:GridTemplateColumn  DataField="MailDate" UniqueName="MailDate" HeaderText="Mailed Date & Name"
                                                HeaderStyle-Width="80px">
                                                    <ItemTemplate>
                                                        <b><%# DateTime.Parse(DataBinder.Eval(Container.DataItem, "MailDate").ToString()).ToShortDateString() %></b>
                                                        <%# DataBinder.Eval(Container.DataItem, "CampaignName")%>
                                                    </ItemTemplate>
                                            </telerik:GridTemplateColumn>
                                            
                                            <telerik:GridTemplateColumn DataField="CampaignNumber" UniqueName="ClientNumber"  HeaderText="Client#" HeaderStyle-Width="30px">
                                                    <ItemTemplate>
                                                        <%# KramerUtils.GetClientNumberFromCampaignNumber(DataBinder.Eval(Container.DataItem, "CampaignNumber").ToString()).PadLeft(4, '0').Substring(0, 4)%>
                                                    </ItemTemplate>
                                            </telerik:GridTemplateColumn>  

                                            <telerik:GridBoundColumn AllowFiltering="true" DataField="MailingNumber" HeaderText="Mail#"
                                                HeaderStyle-Width="20px">
                                            </telerik:GridBoundColumn>

                                            <telerik:GridBoundColumn DataField="LastName" Visible="false" HeaderText="Agent" HeaderStyle-Width="40px" >
                                            </telerik:GridBoundColumn>
                         
                                            <telerik:GridBoundColumn DataField="CampaignResponseId" Visible="false" >
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="ListDataId" Visible="false" >
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="CompanyId" Visible="false" >
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="CampaignId" Visible="false" >
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="CampaignNumber" Visible="false" >
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="CRMTemplateId" Visible="false" >
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="AllowMapping" Visible="false" >
                                            </telerik:GridBoundColumn>                                        
                                            <telerik:GridBoundColumn DataField="PhoneNumber" Visible="false" HeaderText="Home Phone" />
                                            <telerik:GridBoundColumn DataField="WorkPhone" Visible="false" HeaderText="Work Phone" />
                                            <telerik:GridBoundColumn DataField="MobilePhone" Visible="false" HeaderText="Mobile Phone" />
                                            <telerik:GridBoundColumn DataField="Email" Visible="false" HeaderText="Email" />                                 
                                        </Columns>
                                       
                                    </MasterTableView>
                                </telerik:RadGrid>
                                <asp:SqlDataSource runat="server" ID="LeadsObjectDataSource" DataSourceMode="DataReader"
                                    ConnectionString="<%$ ConnectionStrings:KramerConnectionString%>" />
                            </telerik:RadPane>
                        </telerik:RadSplitter>
                    </telerik:RadPane>
                </telerik:RadSplitter>
            </telerik:RadPane>
        </telerik:RadSplitter>
        
     
                <asp:Panel ID="leadPanel" runat="server">
                </asp:Panel>
                    
                
         
                <script type="text/javascript">
                    //var $elem = $('#shablam');
                    //$('html, body').animate({ scrollTop: 530 }, 0);
                
                </script>
    </asp:Content>

    aspx.cs

    public partial class secure_client_Home : PageBaseClient
    {
        private KramerEntities KE = new KramerEntities();
        protected int _useAgentId;

        protected void Page_PreRender(object sender, EventArgs e)
        {
            //if we selected a single lead, select it so it will show the details
            if (Request.QueryString["lid"] != null)
            {
                SelectFirstGridRow();
                GridDataItem dataItem = RadGrid1.SelectedItems[0] as GridDataItem;
               // DisplayLead(dataItem);
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["CurrentAgentId"] == null) Response.Redirect("~/");
            //if this is a Manager, use the passed AgentId
            if (Request.QueryString["aid"] != null)
            {
                _useAgentId = int.Parse(Request.QueryString["aid"].ToString());
            }
            else
            {
                _useAgentId = CurrentAgentId;
            }

            if (IsPostBack)
            {

                //leadviewcontrol.Visible = true;  //Kaushik Commented
                //leadPanel.Controls.Clear();
                
            }
            else
            {
               // LoadUserControl("~/secure/controls/messages/LeadView.ascx",null); //KAushik Added
            }
            if (Request.QueryString["cid"] != null)
            {
                int _passedIncampaignId = 0;
                if (int.TryParse(Request.QueryString["cid"], out _passedIncampaignId))
                {
                    GetCampaignInfo(_passedIncampaignId);
                    //add agents name if it isn't me
                    int campaignAgentId = Manager.GetCampaignAgent(_passedIncampaignId);
                    if (CurrentAgentId != campaignAgentId)
                    {
                        Agents theAgent = Manager.GetAgent(campaignAgentId);
                        string AgentName = theAgent.FirstName + " " + theAgent.LastName;
                        _pageheading.Text = "Campaign Leads for " + AgentName;
                        _pagesubheading.Text = "List of all leads recieved for this campaign.";
                    }
                    else
                    {
                        //add headings
                        _pageheading.Text = "Campaign Leads";
                        _pagesubheading.Text = "List of all leads recieved for this campaign.";
                    }
                }
            }
        }

        protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)
        {
            throw new NotImplementedException();
        }

        private void SelectFirstGridRow()
        {
            GridDataItem firstDataItem = RadGrid1.Items.OfType<GridDataItem>().FirstOrDefault();
            if (firstDataItem != null)
            {
                firstDataItem.Selected = true;
            }
        }

        public SqlDataSource NewLeads(string agentId)
        {
            //load the campaign leads in grid
            LeadsObjectDataSource.SelectCommand =
                "SELECT TOP 500 CampaignResponseId, ld.FirstName, ld.LastName, CompanyId, ResponseName, cr.Address1, cr.Address2, cr.City, Cr.[State], cr.ListDataId, " +
                " cr.Zip, Cr.DateAdded, WasRead, Cr.CampaignId, CRMTemplateId, c.MailDate, c.CampaignName, right(c.CampaignNumber,2) as MailingNumber, c.CampaignNumber, AllowMapping, AllowFullExport, AllowCRM " +
                " FROM CampaignResponses cr " +
                " JOIN Campaigns c ON c.CampaignId = cr.CampaignId " +
                " JOIN ListData ld ON ld.ListDataId = cr.ListDataId " +
                "  WHERE c.AgentId = " + agentId + " and cr.WasRead = 0 ORDER BY CampaignResponseId DESC";
            RadGrid1.MasterTableView.NoMasterRecordsText = "<b>There are currently no New Leads</b>";
            return LeadsObjectDataSource;
        }

       

       

       
        protected void GridRowSelected(object sender, EventArgs e)
        {
            var dataItem = RadGrid1.SelectedItems[0] as GridDataItem;
            if (dataItem != null)
            {
               // DisplayLead(dataItem);
                LoadUserControl("~/secure/controls/messages/LeadView.ascx",dataItem);
            }
        }

      
        protected void DisplayLeadNew(secure_controls_messages_LeadView abc,GridDataItem dataItem)
        {
            if (dataItem != null)
            {
                var listId = dataItem["ListDataId"].Text;
                var responseId = dataItem["CampaignResponseId"].Text;
                var companyId = dataItem["CompanyId"].Text;
                var campaignId = dataItem["CampaignId"].Text;
                var campaignNumber = dataItem["CampaignNumber"].Text;
                var crmTemplateId = dataItem["CRMTemplateId"].Text;
                abc.ListId = int.Parse(listId);
                abc.CompanyId = int.Parse(companyId);
                abc.CampaignId = int.Parse(campaignId);
                abc.ResponseId = int.Parse(responseId);
                abc.ClientNumber = KramerUtils.GetClientNumberFromCampaignNumber(campaignNumber);
                abc.EnableNeighborhoodProgram = bool.Parse(dataItem["AllowMapping"].Text); //Kaushik Commented
                int templateId = 0;
                int.TryParse(crmTemplateId, out templateId);
                abc.CRMTemplateId = templateId;
            }

        }

        protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
        {
            if (e.CommandName == Telerik.Web.UI.RadGrid.ExportToExcelCommandName ||
                e.CommandName == Telerik.Web.UI.RadGrid.ExportToWordCommandName ||
                e.CommandName == Telerik.Web.UI.RadGrid.ExportToCsvCommandName ||
                e.CommandName == Telerik.Web.UI.RadGrid.ExportToPdfCommandName)
            {
                ConfigureExport();
                if (e.CommandName == Telerik.Web.UI.RadGrid.ExportToPdfCommandName)
                {
                    RadGrid1.MasterTableView.GetColumn("FirstName").HeaderStyle.Width = Unit.Pixel(50);
                    RadGrid1.MasterTableView.GetColumn("LastName").HeaderStyle.Width = Unit.Pixel(50);
                    RadGrid1.MasterTableView.GetColumn("Address1").HeaderStyle.Width = Unit.Pixel(150);
                    RadGrid1.MasterTableView.GetColumn("City").HeaderStyle.Width = Unit.Pixel(90);
                    RadGrid1.MasterTableView.GetColumn("State").HeaderStyle.Width = Unit.Pixel(30);
                    RadGrid1.MasterTableView.GetColumn("Zip").HeaderStyle.Width = Unit.Pixel(65);
                    RadGrid1.MasterTableView.GetColumn("DateAdded").HeaderStyle.Width = Unit.Pixel(60);
                    RadGrid1.MasterTableView.GetColumn("MailDate").HeaderStyle.Width = Unit.Pixel(150);
                    RadGrid1.MasterTableView.GetColumn("CompanyId").HeaderStyle.Width = Unit.Pixel(35);
                    RadGrid1.MasterTableView.GetColumn("MailingNumber").HeaderStyle.Width = Unit.Pixel(35);
                    RadGrid1.ExportSettings.ExportOnlyData = false;

                    //re-hide the extra fields
                    RadGrid1.MasterTableView.Columns.FindByDataField("PhoneNumber").Visible = false;
                    RadGrid1.MasterTableView.Columns.FindByDataField("WorkPhone").Visible = false;
                    RadGrid1.MasterTableView.Columns.FindByDataField("MobilePhone").Visible = false;
                    RadGrid1.MasterTableView.Columns.FindByDataField("Email").Visible = false;
                }
            }

            
        }

        protected void RadGrid1_ExcelMLExportRowCreated(object source, Telerik.Web.UI.GridExcelBuilder.GridExportExcelMLRowCreatedArgs e)
        {
            if (e.RowType == Telerik.Web.UI.GridExcelBuilder.GridExportExcelMLRowType.DataRow)
            {
                if (e.Row.Cells[0] != null && ((string)e.Row.Cells[0].Data.DataItem).Contains("U"))
                {
                    e.Row.Cells[0].StyleValue = "MyCustomStyle";
                }
            }
        }


        protected void RadGrid1_ExcelMLExportStylesCreated(object source, Telerik.Web.UI.GridExcelBuilder.GridExportExcelMLStyleCreatedArgs e)
        {
            foreach (Telerik.Web.UI.GridExcelBuilder.StyleElement style in e.Styles)
            {
                if (style.Id == "headerStyle")
                {
                    style.FontStyle.Bold = true;
                    style.FontStyle.Color = System.Drawing.Color.Gainsboro;
                    style.InteriorStyle.Color = System.Drawing.Color.Wheat;
                    style.InteriorStyle.Pattern = Telerik.Web.UI.GridExcelBuilder.InteriorPatternType.Solid;
                }
                else if (style.Id == "itemStyle")
                {
                    style.InteriorStyle.Color = System.Drawing.Color.WhiteSmoke;
                    style.InteriorStyle.Pattern = Telerik.Web.UI.GridExcelBuilder.InteriorPatternType.Solid;
                }
                else if (style.Id == "alternatingItemStyle")
                {
                    style.InteriorStyle.Color = System.Drawing.Color.LightGray;
                    style.InteriorStyle.Pattern = Telerik.Web.UI.GridExcelBuilder.InteriorPatternType.Solid;
                }
            }

            Telerik.Web.UI.GridExcelBuilder.StyleElement myStyle = new Telerik.Web.UI.GridExcelBuilder.StyleElement("MyCustomStyle");
            myStyle.FontStyle.Bold = true;
            myStyle.FontStyle.Italic = true;
            myStyle.InteriorStyle.Color = System.Drawing.Color.Gray;
            myStyle.InteriorStyle.Pattern = Telerik.Web.UI.GridExcelBuilder.InteriorPatternType.Solid;
            e.Styles.Add(myStyle);
        }

        public void ConfigureExport()
        {
            RadGrid1.Width = Unit.Pixel(3000);
            RadGrid1.ExportSettings.ExportOnlyData = true;
            RadGrid1.ExportSettings.IgnorePaging = true;
            RadGrid1.ExportSettings.OpenInNewWindow = true;
            RadGrid1.ExportSettings.FileName = "LeadTracker Leads";
            RadGrid1.ExportSettings.Pdf.PageHeight = Unit.Parse("210mm");
            RadGrid1.ExportSettings.Pdf.PageWidth = Unit.Parse("297mm");
            RadGrid1.GridLines = GridLines.Both;

            RadGrid1.MasterTableView.Columns.FindByUniqueName("ReadIcon").Visible = false;

            if (Request.QueryString["cid"] != null)
            {
                RadGrid1.MasterTableView.Columns.FindByDataField("PhoneNumber").Visible = true;
                RadGrid1.MasterTableView.Columns.FindByDataField("WorkPhone").Visible = true;
                RadGrid1.MasterTableView.Columns.FindByDataField("MobilePhone").Visible = true;
                RadGrid1.MasterTableView.Columns.FindByDataField("Email").Visible = true;
            }
        }

       
       
    The User Control

    <style>
        .savenow{
            background-color:Red;color:White;width:100px;
                margin-top:10px;margin-left:10px;
        }
        .leftcollabel
        {
            width: 100px;
            text-align: right;
            vertical-align: top;
        }
        .leftcoldata
        {
            width: 250px;
        }
        .rightcollabel
        {
            width: 100px;
            vertical-align: top;
        }
        .rightcoldata
        {
            width: 250px;
            text-align: left;
        }
        .colspacer
        {
            width: 30px;
            margin-left: 100px;
        }
        #shablam
        {
            border:solid 1px #dfe9f5;
        }
    </style>

            <telerik:RadScriptBlock runat="server" ID="RadScriptBlock1">

                <script type="text/javascript">
                    function InfoChanged(sender, eventArgs) {
                        //alert('hi');
                        $('.saveLeadInfoButton').removeClass('saveLeadInfoButton')
                            .addClass('savenow');
                    }

                    function onButtonClicked(sender, args) {
                        var button = args.get_item();
                        if (button.get_text() == 'Print Card Only') {
                            window.open('/secure/client/scan/<%=ClientNumber %>/<%=CampaignId %>/<%=ResponseId %>.jpg', 'mywindow');                    
                        }
                        else {
                            window.open('PrintLead.aspx?clid=<%=ClientNumber %>&caid=<%=CampaignId %>&rid=<%=ResponseId %>', 'mywindow');
                        }
                    }

                    function OnClientClicked(sender, eventArgs) {
                        sender.set_text("Please wait...");
                    }


    //                function FieldChanged(sender) {
    //                    //toolbar = $find('<%=saveButton.ClientID %>');
    //                    //toolbar.parent().css('background-color', 'red');
    //                    
    //                    $("#<%=saveButton.ClientID %>").Parent().css("border","3px solid red");
    //                    //sender.className = "modifiedfield";
    //                }
                </script>
            </telerik:RadScriptBlock>

    <div id="shablam" style="min-height:300px;">
    <asp:Panel ID="wholePage" runat="server">

    <telerik:RadTabStrip ID="RadTabStrip1" runat="server" MultiPageID="RadMultiPage1" Style="padding-top:4px;padding-left:10px;" SelectedIndex="0" BorderColor="Black"  BackColor="#D8EEF3">
        <Tabs>
            <telerik:RadTab runat="server" Text="Lead Info" />
            <telerik:RadTab runat="server" Text="Details" />
            <telerik:RadTab runat="server" Text="Follow Up" />
            <telerik:RadTab runat="server" Text="Sale Details" />
        </Tabs>
    </telerik:RadTabStrip>
    <telerik:RadButton OnClick="SaveLeadInfo" ID="saveButton" Text="Save Changes" runat="server" CssClass="saveLeadInfoButton"  />
    <div style="float:right;">
        <telerik:RadButton OnClick="MarkAsNew" ID="markAsNew" Text="Mark As New" runat="server" OnClientClicked="OnClientClicked"  />
    </div>
    <asp:HyperLink runat="server" ID="_reassignLeadLink" CssClass="reassignLink" Text="Reassign This Lead" Visible="false" />

    <div class="multiPage_wrapper">
        <telerik:RadMultiPage ID="RadMultiPage1" runat="server" SelectedIndex="0">
            <telerik:RadPageView ID="RadPageView1" runat="server" CssClass="tabpage">

                <table border="0" width="900px">
                    <tr>
                        <td class="leftcollabel" align="right">
                            <a style="border:solid 1px red;background-color:Yellow;padding:3px;cursor:pointer;" class="nav_down" id="nav_down" >View Card</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  Name:
                        </td>
                        <td class="leftcoldata">
                            <telerik:RadTextBox runat="server" ID="_txtName" Width="200" />
                            <asp:HiddenField ID="_ResponseId" runat="server" />
                        </td>
                        <td class="colspacer">
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        </td>
                        <td class="rightcollabel" align="right">
                            Status:
                        </td>
                        <td class="rightcoldata">
                            <asp:DropDownList runat="server" ID="_statusListbox">
                                <asp:ListItem Value="1" Text="New Lead" />
                                <asp:ListItem Value="2" Text="Good Prospect" />
                                <asp:ListItem Value="3" Text="Appointment Made" />
                                <asp:ListItem Value="4" Text="Application Submitted" />
                                <asp:ListItem Value="10" Text="Working" />
                                <asp:ListItem Value="5" Text="Closed/Sold" />
                                <asp:ListItem Value="6" Text="Not Interested" />
                                <asp:ListItem Value="7" Text="Not Qualified (Financial)" />
                                <asp:ListItem Value="8" Text="Not Qualified (Health)" />
                                <asp:ListItem Value="9" Text="Existing Client" />
                            </asp:DropDownList>
                            <asp:CheckBox runat="server" ID="_existingClient" /> Existing Client
                        </td>
                    </tr>
                    <tr>
                        <td class="leftcollabel" align="right">
                            Address1:
                        </td>
                        <td class="leftcoldata">
                            <telerik:RadTextBox runat="server" ID="_txtAddress1" Width="200" ClientEvents-OnValueChanged="InfoChanged" />
                        </td>
                        <td class="colspacer">
                        </td>
                        <td class="rightcollabel" align="right">
                            Email:
                        </td>
                        <td class="rightcoldata">
                            <telerik:RadTextBox runat="server" ID="_email" Width="200" />
                        </td>
                    </tr>
                    <tr>
                        <td class="leftcollabel" align="right">
                            Address2:
                        </td>
                        <td class="leftcoldata">
                            <telerik:RadTextBox runat="server" ID="_txtAddress2" Width="200" />
                        </td>
                        <td class="colspacer">
                        </td>
                        <td class="rightcollabel" align="right">
                            Home Phone:
                        </td>
                        <td class="rightcoldata">
                            <telerik:RadTextBox runat="server" ID="_homePhone" Width="200" />
                        </td>
                    </tr>
                    <tr>
                        <td class="leftcollabel" valign="top" align="right">
                            City/ST/Zip:
                        </td>
                        <td class="leftcoldata" valign="top">
                            <telerik:RadTextBox runat="server" ID="_City" Width="130" />
                            <telerik:RadTextBox Width="20" runat="server" ID="_State" />
                            <telerik:RadTextBox runat="server" ID="_Zip" Width="50" />
                        </td>
                        <td class="colspacer">
                        </td>
                        <td class="rightcollabel" valign="top" align="right">
                            Work Phone:
                        </td>
                        <td class="rightcoldata">
                             <telerik:RadTextBox runat="server" ID="_workPhone" Width="200" />
                        </td>
                    </tr>
                    <tr>
                        <td class="leftcollabel" valign="top" align="right">
                            Maps:
                        </td>
                        <td class="leftcoldata" valign="top">
                            <a runat="server" id="_googleMapLink" target="_blank"><img alt="Google Map" id="Img1" runat="server" src="~/images/googleMapsIcon.jpg" border="0" /></a>&nbsp;&nbsp;
                            <telerik:RadToolTip ID="RadToolTip1" Position="TopCenter" Skin="Windows7" runat="server" Text="Google Maps" TargetControlID="_googleMapLink" />
                            <a runat="server" id="_yahooMapLink" target="_blank"><img alt="Yahoo Map" id="Img2" runat="server" src="~/images/YahooMapsIcon.gif" border="0" /></a>&nbsp;
                            <telerik:RadToolTip ID="RadToolTip2" Position="TopCenter" Skin="Windows7" runat="server" Text="Yahoo Maps" TargetControlID="_yahooMapLink" />
                            <a runat="server" id="_mapquestLink" target="_blank"><img alt="Mapquest Map" id="Img3" runat="server" src="~/images/MapquestIcon.gif" border="0" /></a>
                            <telerik:RadToolTip ID="RadToolTip3" Position="TopCenter" Skin="Windows7" runat="server" Text="Mapquest Map" TargetControlID="_mapquestLink" />
                            

                        </td>
                        <td class="colspacer">
                        </td>
                        <td class="rightcollabel" valign="top" align="right">
                            Mobile Phone:
                        </td>
                        <td class="rightcoldata">
                            <telerik:RadTextBox runat="server" ID="_mobilePhone" Width="200" />
                        </td>
                    </tr>              
                                    <tr>
                        <td class="leftcollabel" valign="top" align="right">
                            Neighborhood&nbsp;Leads:
                        </td>
                        <td class="leftcoldata" valign="top">
                            <a runat="server" id="_neighborhoodLink"><img alt="Neighborhood Program" id="Img4" runat="server" src="~/images/icon_people.png" border="0" /></a>
                            <telerik:RadToolTip ID="RadToolTip4" Position="TopCenter" Skin="Windows7" runat="server" Text="Neighborhood Program" TargetControlID="_neighborhoodLink" />
                            <asp:Literal runat=server ID="NPNotAvailable" />
                        </td>
                        <td class="colspacer">
                        </td>
                        <td class="rightcollabel" valign="top" align="right">

                        </td>
                        <td class="rightcoldata">

                        </td>
                    </tr>

                </table>
                          <asp:Panel runat="server" ID="Panel2" GroupingText="Notes" CssClass="noteslist" ScrollBars="Vertical" Height="160px">
                                <asp:Repeater runat="server" ID="_notesRepeater" OnItemCommand="DeleteNote" >
                                    <ItemTemplate>
                                        <div class="note">
                                            <div class="notepad-01"></div>
                                            <div class="notepad-02">
                                                <div class="notetext">
                                                    <b><%# ((DateTime)DataBinder.Eval(Container.DataItem, "StartDate")).ToString("MMMM d, yyyy, h:mm tt")%></b>
                                                    <div style="float:right;padding-right:14px;">
                             <asp:LinkButton ID="_deleteNote" runat="server" Text="" CommandName="ID"
                ToolTip="Delete item" OnClientClick="if (!confirm('Are you sure you want to delete this note?')) { return false; };">
                
                <asp:Image ID="imgDelete" runat="server" ImageUrl="~/images/deleteIcon.gif" AlternateText="Delete Item" />
                             </asp:LinkButton>
                              </div>
                                                    <br />
                                                    <%# ((string)DataBinder.Eval(Container.DataItem, "EventNotes")).Replace("\n", "<br />") %>
                                                    <asp:HiddenField ID="_noteId" runat="server" Value='<%# DataBinder.Eval(Container.DataItem, "EventId") %>' />
                                                </div>
                                            </div>
                                            <div class="notepad-03"></div>
                                        </div>
                                    </ItemTemplate>
                                </asp:Repeater>
                                <asp:Label runat="server" ID="_noNotesLabel" Visible="false" Text="No notes yet"></asp:Label>
                            </asp:Panel>
                            <asp:Panel runat="server" ID="Panel1" GroupingText="Add a note" Width="270px" Height="160px">
                                Note:
                                <telerik:RadTextBox TextMode="MultiLine" runat="server" Rows="6" Width="240px" MaxLength="1000" ID="_NoteText">
                                </telerik:RadTextBox><br />
                                <div style="text-align:right;">
                                <input type="button" id="btnAddNote" runat="server" value=" Add Note " onserverclick="AddNote" onclick="this.disabled=true;this.value='Adding Note';">
                            </asp:Panel>
                            <br />
                <telerik:RadToolBar runat="server" ID="RadToolBar1" CssClass="inbox-search-toolbar"
                    OnClientButtonClicked="onButtonClicked" EnableViewState="false">
                    <Items>
                        <telerik:RadToolBarDropDown ImageUrl="~/Images/print.gif" Text="Print">
                            <Buttons>
                                <telerik:RadToolBarButton Text="Print Card Only" id="shizz" CommandArgument="cardonly" Enabled="true" />
                                <telerik:RadToolBarButton Text="Print Card and Notes" id="zam" CommandArgument="cardandnotes" Enabled="true" />
                            </Buttons>
                        </telerik:RadToolBarDropDown>
                    </Items>
                </telerik:RadToolBar>
                
                <telerik:RadSplitter runat="server" ID="RadSplitter1" Width="100%" BorderSize="0"
                    BorderStyle="None" PanesBorderSize="0" Height="100%" Orientation="Horizontal">
                </telerik:RadSplitter>
                <img src="" runat="server" id="leadImage" /><br />
                <br />
                <div style="padding-left:300px;">
                            <a style="border:solid 1px red;background-color:Yellow;padding:3px;cursor:pointer;" class="nav_up" id="nav_up">Back to Top</a>
                </div><br />
            </telerik:RadPageView>
            <telerik:RadPageView runat="server" id="RadPageViewCRMTemplate" CssClass="tabpage">
                <div style="float:left;padding-right:80px">
                        <table>
                            <tr>
                                <td class="leftcollabel" valign="top" align="right">
                                    Birthday:
                                </td>
                                <td class="leftcoldata" valign="top">
                                    Month:<telerik:RadTextBox runat="server" ID="_birthdayMonth" Width="20" />
                                    Day:<telerik:RadTextBox runat="server" ID="_birthdayDay" Width="20" />
                                    Year:<telerik:RadTextBox Width="40" runat="server" ID="_birthdayYear" />
                                </td>
                            </tr><tr>
                            </td>
                            <td class="rightcollabel" valign="top" align="right">
                                Height:
                            </td>
                            <td class="rightcoldata">
                                 <telerik:RadTextBox runat="server" ID="_height" Width="30" />
                                 Weight:<telerik:RadTextBox runat="server" ID="_weight" Width="30" />
                            </td>
                        </tr>
                        <tr>
                            <td class="leftcollabel" valign="top" align="right">
                                Spouse:
                            </td>
                            <td class="leftcoldata" valign="top">
                                <telerik:RadTextBox runat="server" ID="_spouse" Width="200" />
                            </td>
                        </tr>
                        <tr>
                            <td class="rightcollabel" valign="top" align="right">
                                Children:
                            </td>
                            <td class="rightcoldata">
                                 <telerik:RadTextBox runat="server" ID="_children" Width="200" />
                            </td>
                        </tr>                
                        <tr>
                            <td class="rightcollabel" valign="top" align="right">
                                Employer:
                            </td>
                            <td class="rightcoldata">
                                 <telerik:RadTextBox runat="server" ID="_employer" Width="200" />
                            </td>
                        </tr>       
                    </table>
                </div>
                
                <div style="">     
                    <asp:Panel runat="server" ID="CRMTemplatePanel">
                    </asp:Panel>
                  </div>
          </telerik:RadPageView>
            <telerik:RadPageView ID="RadPageView2" runat="server" CssClass="tabpage">
                <table width="900px">
                    <tr>
                        <td width="500px;" valign="top">
                            Called Back: <telerik:RadDatePicker runat="server" ID="_calledBackDate" /> <a href"#">today</a>
                            <br />
                            Appointment Made: <telerik:RadDatePicker runat="server" ID="_appointmentMadeDate" /> <a href"#">today</a>
                            <br />
                            App Submitted:<telerik:RadDatePicker runat="server" ID="_applicationSubmittedDate" /> <a href"#">today</a>
                            <br />
                            Policy Info Entered: <telerik:RadDatePicker runat="server" ID="_policyInfoEnteredDate" /> <a href"#">today</a>
                            <br />
                            App Rejected: <telerik:RadDatePicker runat="server" ID="_appRejectedDate" /> <a href"#">today</a>
                            <br />
                        </td>
                        <td>
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        </td>
                        <td valign="top">
                            <asp:Panel runat="server" ID="AppointmentAddPanel" GroupingText="Add an appointment">
                                Appointment Title: <telerik:RadTextBox Width="400px" runat="server" ID="_AppointmentTitle" /><br />
                                Contact On: <telerik:RadDateTimePicker ID="_appointmentDateTime" runat="server">
                                </telerik:RadDateTimePicker>
                                <br />
                                <telerik:RadTextBox TextMode="MultiLine" runat="server" Rows="5" Width="400px" ID="_AppointmentNotes" >
                                </telerik:RadTextBox><br />
                                <input type="button" id="Button2" runat="server" value=" Add Appointment " onserverclick="AddAppointment" onclick="this.disabled=true;this.value='Adding Appointment';">
                            </asp:Panel>
                                <br />
                            <asp:Panel runat="server" ID="AppointmentsListPanel" GroupingText="Upcoming Appointments">
                                <asp:Repeater runat="server" ID="_eventsRepeater" OnItemCommand="DeleteAppointment"  >
                                    <ItemTemplate>
                                        <%# ((DateTime)DataBinder.Eval(Container.DataItem, "StartDate")).ToString("dddd, dd MMMM yyyy hh:mm tt") %> - <%# DataBinder.Eval(Container.DataItem, "EventTitle") %>
                                        
                                        
                                    <asp:LinkButton ID="_deleteAppt" runat="server" Text="" CommandName="ID"
                ToolTip="Delete item" OnClientClick="if (!confirm('Are you sure you want to delete this appointment?')) { return false; };">
                
                                        <asp:Image ID="_imgDeleteAppt" runat="server" ImageUrl="~/images/deleteIcon.gif" AlternateText="Delete Appointment" />
                                    </asp:LinkButton>                                    
                                        <asp:HiddenField ID="_eventId" runat="server" Value='<%# DataBinder.Eval(Container.DataItem, "EventId") %>' />
                                        <br />
                                    </ItemTemplate>
                                </asp:Repeater>
                            </asp:Panel>
                        </td>
                    </tr>
                </table>
            </telerik:RadPageView>
            <telerik:RadPageView ID="RadPageView3" runat="server" CssClass="tabpage">
                <table width="600px" padding="10px;">
                    <tr>
                        <td align="right">
                            Sold Date:
                        </td>
                        <td>
                            <telerik:RadDatePicker ID="_soldDate" runat="server">
                            </telerik:RadDatePicker>
                        </td>
                    </tr>
                    <tr>
                        <td align="right">
                            X-Date:
                        </td>
                        <td>
                            <telerik:RadDatePicker ID="_xDate" runat="server">
                            </telerik:RadDatePicker>
                        </td>
                    </tr>
                    <tr>
                        <td align="right">
                            Commission:
                        </td>
                        <td>
                            $<telerik:RadTextBox ID="_commission" runat="server">
                            </telerik:RadTextBox>
                        </td>
                    </tr>
                    <tr>
                        <td align="right">
                            Sold/Placed:
                        </td>
                        <td>
                            <telerik:RadTextBox runat="server" ID="_soldPlaced" EmptyMessage="Carrier Name/Policy Specifics" />
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">
                            <telerik:RadTextBox ID="_saleNotes" TextMode="MultiLine" runat="server" Rows="5"
                                Width="400px" EmptyMessage="Enter notes about the sale">
                            </telerik:RadTextBox><br />
                        </td>
                    </tr>
                </table>
            </telerik:RadPageView>
        </telerik:RadMultiPage>
    </div>
    </asp:Panel>

        <telerik:RadWindowManager ID="RadWindowManager1" runat="server" EnableShadow="true">
            <Windows>
                <telerik:RadWindow ID="RadWindow1" runat="server" ShowContentDuringLoad="false" Width="400px"
                    Height="300px" Title="Select an agent" Behaviors="Close,Reload" Modal="true">
                </telerik:RadWindow>
            </Windows>
        </telerik:RadWindowManager>
                
        <script type="text/javascript">
            //<![CDATA[
            function openRadWin(agentid) {
                radopen("SelectAgent.aspx?id=" + agentid, "RadWindow1");
            }
            //]]>                                                                        
        </script>

        <asp:Panel runat="server" ID="_agentSelectPanel" Visible="false">
            <button style="width: 150px; margin-bottom: 3px;" onclick="openRadWin('<asp:Literal runat='server' id='theAgentId' />'); return false;">
                Select Agents</button>
        </asp:Panel>
        
        
    </div>

            <script>
                $(function() {
                    var $elem = $('#wrapper');

                    $(window).bind('scrollstart', function() {
                        $('#nav_up,#nav_down').stop().animate({ 'opacity': '0.2' });
                    });
                    $(window).bind('scrollstop', function() {
                        $('#nav_up,#nav_down').stop().animate({ 'opacity': '1' });
                    });

                    $('#nav_down').click(
                        function(e) {
                            $('html, body').animate({ scrollTop: $elem.height() }, 2000);
                        }
                    );
                    $('#nav_up').click(
                        function(e) {
                            $('html, body').animate({ scrollTop: '0px' }, 800);
                        }
                    );
                });
            </script>



    public partial class secure_controls_messages_LeadView : System.Web.UI.UserControl
    {
       
        public int ResponseId
        {
            get
            {
                if (ViewState["ResponseId"] != null) return (int)ViewState["ResponseId"];
                else return 0;
            }
            set { ViewState["ResponseId"] = value; }
        }

        public int ListId
        {
            get
            {
                if (ViewState["ListId"] != null) return (int)ViewState["ListId"];
                else return 0;
            }
            set { ViewState["ListId"] = value; }
        }

        public int CampaignId
        {
            get
            {
                if (ViewState["CampaignId"] != null) return (int)ViewState["CampaignId"];
                else return 0;
            }
            set { ViewState["CampaignId"] = value; }
        }

        public int CompanyId
        {
            get
            {
                if (ViewState["CompanyId"] != null) return (int)ViewState["CompanyId"];
                else return 0;
            }
            set { ViewState["CompanyId"] = value; }
        }

        public string ClientNumber
        {
            get
            {
                if (ViewState["ClientNumber"] != null) return (string)ViewState["ClientNumber"];
                else return "";
            }
            set { ViewState["ClientNumber"] = value; }
        }

        public int CRMTemplateId
        {
            get
            {
                if (ViewState["CRMTemplateId"] != null) return (int)ViewState["CRMTemplateId"];
                else return 0;
            }
            set { ViewState["CRMTemplateId"] = value; }
        }

        public bool EnableCRM
        {
            get
            {
                if (ViewState["EnableCRM"] != null) return (bool)ViewState["EnableCRM"];
                else return true;
            }
            set { ViewState["EnableCRM"] = value; }
        }

        public bool EnableNeighborhoodProgram
        {
            get
            {
                if (ViewState["EnableNeighborhoodProgram"] != null) return (bool)ViewState["EnableNeighborhoodProgram"];
                else return false;
            }
            set { ViewState["EnableNeighborhoodProgram"] = value; }
        }

        protected int _responseId;
        protected int _listId;
        protected int _useAgentId;

        private KramerEntities KE = new KramerEntities();
        private CRMLead lead;

        protected void Page_PreRender(object sender, EventArgs e)
        {
            //check security
            if (ListId != 0)
            {
                setAgentId();

                //record history
                if (Session["CurrentAgentId"] == null) Response.Redirect("~/");
                int agentId = (int) Session["CurrentAgentId"];
                string historySQL =
                    string.Format(
                        "INSERT INTO [ViewHistory] ([AgentId],[CampaignResponseId]) VALUES ({0},{1})",
                        agentId, ResponseId);
                int rowsAffected;
                KE.ExecuteNonQuery(historySQL, out rowsAffected);

                wholePage.Visible = true;
                lead = new CRMLead().GetLead(ListId, _markAsRead);

                _ResponseId.Value = ResponseId.ToString();
                PopulateLeadInfo();

                string GoogleMaplink = string.Format("http://maps.google.com/maps?q={0},+{1},+{2}&z=16", lead.LeadListData.Address1,
                                               lead.LeadListData.City, lead.LeadListData.St);
                string MapquestMaplink =
                    string.Format("http://www.mapquest.com/maps?city={1}&state={2}&address={0}&zipcode={3}&country=US",
                                  lead.LeadListData.Address1,
                                  lead.LeadListData.City, lead.LeadListData.St, lead.LeadListData.ZIP);
                string YahooMaplink = string.Format("http://maps.yahoo.com/#mvt=m&zoom=17&q1={0}%2C%20{1}%2C%20{2}%2C {3}",
                                  lead.LeadListData.Address1,
                                  lead.LeadListData.City, lead.LeadListData.St, lead.LeadListData.ZIP);

                bool showNeighborhoodLink = EnableNeighborhoodProgram;
                //check to see if this is a PO Box
                if (lead.LeadResponse.Address1.ToLower().Contains("po box") || lead.LeadListData.Long == null) showNeighborhoodLink = false;
                string NeighborhoodLink = "";
                if (showNeighborhoodLink)
                {
                    NeighborhoodLink = string.Format("~/secure/client/Map.aspx?id={0}", lead.LeadListData.ListDataId);
                    _neighborhoodLink.HRef = NeighborhoodLink;
                    NPNotAvailable.Visible = false;
                    _neighborhoodLink.Visible = true;
                }
                else if (lead.LeadResponse.Address1.ToLower().Contains("po box"))
                {
                    _neighborhoodLink.Visible = false;
                    NPNotAvailable.Text = "<span style='color:#555555;'>Not available for PO Boxes.</span>";
                }
                else if (lead.LeadListData.Long == null)
                {
                    _neighborhoodLink.Visible = false;
                    NPNotAvailable.Text = "<span style='color:#555555;'>Geocode data not available for this lead.</span>";
                }
                else
                {
                    _neighborhoodLink.Visible = false;
                    NPNotAvailable.Text = "<span style='color:#555555;'>Please contact your Marketing Director at <br>888-572-6373 to enable the Neighborhood Program.</span>";
                }

                _googleMapLink.HRef = GoogleMaplink;
                _mapquestLink.HRef = MapquestMaplink;
                _yahooMapLink.HRef = YahooMaplink;

                //companyId/campaignId/responseId
                leadImage.Src = string.Format("http://leadtracker.kramerdirect.com/secure/client/scan/{0}/{1}/{2}.jpg", ClientNumber, CampaignId, ResponseId);

                //enable CRM if needed
                _txtName.Enabled = EnableCRM;

                showAppointments();
                ShowNotes();
            }
            else
            {
               // wholePage.Visible = false; KAushik Commented
                wholePage.Visible = true; //KAushik Added
            }
        }

        private void setAgentId()
        {
            if (Session["CurrentAgentId"] == null) Response.Redirect("~/");
            int agentId = (int)Session["CurrentAgentId"];

            if (Request.Cookies["KramerRole"].Value == "manager")
            {
                //TODO: finish this
                //_reassignLeadLink.Visible = true;
                //_reassignLeadLink.NavigateUrl = "javascript:openRadWin(" + Session["CurrentAgentId"] + ");";

                //get the campaigns agent
                if (_useAgentId == 0)
                    _useAgentId = Manager.GetCampaignAgent(CampaignId);
            }
            else
            {
                _useAgentId = agentId;
            }

        }

        protected  void Page_Load(object sender, EventArgs e)
        {
            
        }

      
       

        //protected void Page_Load(object sender, EventArgs e)
        //{
        //    Button MyButton = (Button)Page.FindControl("AddAppointmentButton");
        //    Panel MyPanel = (Panel)Page.FindControl("AppointmentsListPanel");
        //    RadAjaxManager myAjax = (RadAjaxManager) Page.Master.FindControl("RadAjaxManager1");
        //    myAjax.AjaxSettings.AddAjaxSetting(MyButton, MyPanel);

        //}


        protected void AddAppointment(object sender, EventArgs e)
        {
            setAgentId();
            int agentId = _useAgentId;
            DateTime appointmentTime = (DateTime)_appointmentDateTime.DbSelectedDate;
            EventManager.AddNewEvent(agentId, agentId, _AppointmentTitle.Text.Trim(), _AppointmentNotes.Text.Trim(), appointmentTime, appointmentTime.AddHours(1), int.Parse(_ResponseId.Value), (int)EventManager.EventTypes.ResponseFollowUp);
            showAppointments();
        }

        protected void showAppointments()
        {
            setAgentId();
            int agentId = _useAgentId;
            var theEvents = EventManager.GetEvents(agentId, int.Parse(_ResponseId.Value), DateTime.Now);
            _eventsRepeater.DataSource = theEvents;
            _AppointmentTitle.Text = "";
            _AppointmentNotes.Text = "";
            _appointmentDateTime.Clear();
            _eventsRepeater.DataBind();
        }

        protected void DeleteAppointment(object source, RepeaterCommandEventArgs e)
        {
                   if (e.CommandName == "ID")
                   {
                       string eventId = ((HiddenField) e.Item.FindControl("_eventId")).Value;
                       EventManager.DeleteEvent(int.Parse(eventId));
                       showAppointments();
                   }
        }

        /*******
         *Notes*
         *******/

        protected void AddNote(object sender, EventArgs e)
        {
            setAgentId();
            int agentId = _useAgentId;
            DateTime noteTime = DateTime.Now;
            Log.Debug(string.Format("Note text is: '{0}'", _NoteText.Text));
            Log.Debug(string.Format("Adding new Note via EventManager.AddNewEvent: AgentId = '{0}', Title = 'Note', Notes = '{1}'", agentId, _NoteText.Text.Trim()));
            EventManager.AddNewEvent(agentId, agentId, "Note", _NoteText.Text.Trim(), noteTime, noteTime, int.Parse(_ResponseId.Value), (int)EventManager.EventTypes.ResponseNote);
            _NoteText.Text = "";
            ShowNotes();
        }

        protected void ShowNotes()
        {
            setAgentId();
            int agentId = _useAgentId;
            var theNotes = EventManager.GetNotes(agentId, int.Parse(_ResponseId.Value));
            if (theNotes.Count == 0) _noNotesLabel.Visible = true; else _noNotesLabel.Visible = false;
            _notesRepeater.DataSource = theNotes;
            _NoteText.Text = "";
            _notesRepeater.DataBind();
        }

        protected void DeleteNote(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "ID")
            {
                string noteId = ((HiddenField)e.Item.FindControl("_noteId")).Value;
                EventManager.DeleteEvent(int.Parse(noteId));
                ShowNotes();
            }
        }

        protected void SaveLeadInfo(object sender, EventArgs e)
        {
            LeadEntities LE = new LeadEntities();
            bool isNew = false;

            Leads leaddata = (from x in LE.Leads
                           where x.ListDataId == ListId
                           select x).FirstOrDefault();

            if (leaddata == null)
            {
                leaddata = new Leads();
                leaddata.ListDataId = ListId;
                leaddata.DateAdded = DateTime.Now;
                isNew = true;
                
            }

            //get lead info
            leaddata.FirstName = _txtName.Text.Trim();
            leaddata.LastModifiedDate = DateTime.Now;
            leaddata.Address1 = _txtAddress1.Text.Trim();
            leaddata.Address2 = _txtAddress2.Text.Trim();
            leaddata.City = _City.Text.Trim();
            leaddata.State = _State.Text.Trim();
            leaddata.Zip = _Zip.Text.Trim();
            leaddata.Status = int.Parse(_statusListbox.SelectedValue);
            leaddata.Sold = _existingClient.Checked;
            leaddata.Email = _email.Text.Trim();
            leaddata.HomePhone = _homePhone.Text.Trim();
            leaddata.WorkPhone = _workPhone.Text.Trim();
            leaddata.MobilePhone = _mobilePhone.Text.Trim();

            int testInt;
            DateTime testDate;
            if (DateTime.TryParse(_birthdayMonth.Text.Trim() + "-" + _birthdayDay.Text.Trim() + "-" + _birthdayYear.Text.Trim(),out testDate))
                leaddata.Birthday = testDate;
            leaddata.Height = _height.Text.Trim();
            if (int.TryParse(_weight.Text.Trim(),out testInt)) leaddata.Weight = int.Parse(_weight.Text.Trim());
            leaddata.Spouse = _spouse.Text.Trim();
            leaddata.Children = _children.Text.Trim();
            leaddata.Employer = _employer.Text.Trim();

            //****Follow Up tab****
            leaddata.CalledBackDate = _calledBackDate.IsEmpty
                                          ? (DateTime?) null
                                          : DateTime.Parse(_calledBackDate.DbSelectedDate.ToString());

            leaddata.AppointmentMadeDate = _appointmentMadeDate.IsEmpty
                                               ? (DateTime?) null
                                               : DateTime.Parse(_appointmentMadeDate.DbSelectedDate.ToString());

            leaddata.ApplicationSubmittedDate = _applicationSubmittedDate.IsEmpty
                                                    ? (DateTime?) null
                                                    : DateTime.Parse(_applicationSubmittedDate.DbSelectedDate.ToString());

            leaddata.PolicyEnteredDate = _policyInfoEnteredDate.IsEmpty
                                             ? (DateTime?) null
                                             : DateTime.Parse(_policyInfoEnteredDate.DbSelectedDate.ToString());

            leaddata.AppRejectedDate = _appRejectedDate.IsEmpty
                                           ? (DateTime?) null
                                           : DateTime.Parse(_appRejectedDate.DbSelectedDate.ToString());

            //****Sale Details tab****
            leaddata.SoldDate = _soldDate.IsEmpty
                                    ? (DateTime?)null
                                    : DateTime.Parse(_soldDate.DbSelectedDate.ToString());

            leaddata.XDate = _xDate.IsEmpty
                                    ? (DateTime?)null
                                    : DateTime.Parse(_xDate.DbSelectedDate.ToString());

            decimal testDec;
            if (decimal.TryParse(_commission.Text.Trim(),out testDec)) leaddata.Commission = testDec;

            leaddata.VendorName = _soldPlaced.Text.Trim();
            leaddata.SaleNotes = _saleNotes.Text.Trim();
             
            if (isNew)
            {
                LE.AddToLeads(leaddata);
                LE.SaveChanges();
            }
            else
            {
                LE.SaveChanges();
            }
        }

        protected void MarkAsNew(object sender, EventArgs e)
        {
            CampaignResponses campaignResponse = KE.CampaignResponses.FirstOrDefault(x => x.CampaignResponseId == ResponseId);
            if (null != campaignResponse)
            {
               
            }
        }
    }   


Back to Top