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

Input from RadTextBox to RadPanelBar issues

1 Answer 100 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
Lindsey Kelly
Top achievements
Rank 1
Lindsey Kelly asked on 23 Oct 2009, 08:37 PM
Running into a few issues here.  The functionality we want this application to have is quite simple.  We have a "notes" control with a RadAjaxPanel that consists of a RadTextBox and also a RadPanelBar within another RadAjaxPanel. Notes that are already in the database will populate into their own RadPanelbar items when the page is loaded.  The user enters some text into the RadTextBox and clicks "save."  For some strange reason, once the save button is clicked - the RadPanelBar disappears and is not shown again unless the whole control is closed and reopened.  Another strange issue is that every now and then, the text will not save if it is entered and the save button is clicked too quickly.




<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Notes.ascx.cs" Inherits="Notes" %> 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
<html> 
<head> 
    <style type="text/css"
        body 
        { 
            background-color: #d3d3d3; 
        } 
        img 
        { 
            border: none; 
        } 
        .notesblock 
        { 
            width: 99%; 
            margin: 0 0 0 0; 
        } 
        .noteslist 
        { 
            color: #8a8c8f; 
            list-style-type: none; 
            padding: 0px 1px; 
            font-family: "Lucida Grande" , "Segoe UI" , "Bitstream Vera Sans" , Tahoma, Verdana, Arial,sans-serif; 
            font-size: 10px; 
            line-height: 160%; 
        } 
        #saveButton 
        { 
            position: absolute; 
            top: 280px; 
            right: 75px; 
        } 
        #cancelButton 
        { 
            position: absolute; 
            top: 280px; 
            right: 12px; 
        } 
        #expandButton 
        { 
            position: absolute; 
            top: 20px; 
            right: 5px; 
        } 
 
    </style> 
 
    <script type="text/javascript"
        function clearText(field) { 
 
            var selectString = "Click to Enter New Note"
 
            if (field.defaultValue == selectString) field.value = ''
 
            //        if (field.defaultValue == selectString) field.value = ''
            //        else if (field.value == '') fieldfield.value = field.defaultValue;     
        } 
 
 
        function resizeTB() { 
            var tb = $find("<%= txtUserNote.ClientID %>"); 
//            tb._originalTextBoxCssText = "width:99%;height:35px;"
//            tb.updateCssClass(); 
 
            return false; 
        } 
 
 
        function ButtonClick(sender, e) { 
            var radTextBox = sender
            radTextBox.raisePostBackEvent(); 
        } 
 
    </script> 
 
</head> 
<body bgcolor="#F4F4F4" runat="server" id="MainBody"
    <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" Height="100%" Width="100%"
        <asp:Literal ID="notesHeader" runat="server"
        </asp:Literal> 
        <telerik:RadTextBox ID="txtUserNote" runat="server" TextMode="MultiLine" Width="99%" 
            Height="15px" Visible="False" EmptyMessage="Click to Enter New Note" Font-Size="10px" 
            AutoPostBack="true"
        </telerik:RadTextBox> 
        <div id="expandButton"
            <asp:ImageButton runat="server" ID="expandTbButton" ImageUrl="images/expand.gif" 
                OnClientClick="return resizeTB()" /> 
        </div> 
        <div id="saveButton"
            <asp:Button ID="SaveButton" Height="20px" Font-Size="10px" runat="server" Text="Save" 
                Visible="False" OnClick="SaveButton_Click" /> 
        </div> 
        <div id="cancelButton"
            <asp:Button ID="CancelButton" Height="20px" Font-Size="10px" runat="server" Text="Cancel" 
                OnClick="CancelButton_Click" Visible="False" /> 
        </div> 
    </telerik:RadAjaxPanel> 
    <div id="allnotes"
        <telerik:RadAjaxPanel ID="RadAjaxPanel2" runat="server" Width="562px" Style="background-color: #d3d3d3;"
            <telerik:RadPanelBar ID="RadPanelBar1" runat="server" Style="background-color: #d3d3d3;" 
                EnableEmbeddedSkins="false" Skin="Custom" Height="200px" Width="562px" ExpandMode="FullExpandedItem"
            </telerik:RadPanelBar> 
        </telerik:RadAjaxPanel> 
    </div> 
</body> 
</html> 
 
 
 
 
    public partial class Notes : System.Web.UI.UserControl, IPostBackDataHandler 
    { 
        #region variables 
        private string noteText = string.Empty; 
        private string userNote = string.Empty; 
        private string sessionNoteKey = "4"
        private string modeKey = "5"
        private string tempNoteTextKey = "6"
        public static string invoiceNotesObjectKey = "7"
        #endregion 
 
        #region Page event handlers 
        protected void Page_Load(object sender, EventArgs e) 
        { 
            Notes notes = (Notes)Session[invoiceNotesObjectKey]; 
 
            LoadNoteHistory(notes); 
 
            if (notes == null) 
            { 
                notes = new Notes(); 
            } 
 
            txtUserNote.Visible = true
            CancelButton.Visible = true
            SaveButton.Visible = true
 
        } 
        #endregion 
 
        #region enumerations 
        private enum Mode 
        { 
            Delete = 0
            Edit, 
            New 
        } 
        #endregion 
 
        #region properties 
        public string NoteText 
        { 
            get { return noteText; } 
            set { noteText = value; } 
        } 
 
        public string UserNote 
        { 
            get { return userNote; } 
            set { userNote = value; } 
        } 
        #endregion 
 
        #region public methods 
        public void AddNote(Invoice invoice) 
        { 
            Notes notes = ((Notes)Session[this.sessionNoteKey]); 
            Note note = notes[notes.Count - 1]; 
            note.DateTime = System.DateTime.Now; 
            note.DocId = invoice.ID; 
            note.Username = invoice.Username; 
            note.Save = true
            invoice.Notes.Add(note); 
        } 
 
 
        public bool LoadNoteHistory(Notes notes) 
        { 
            StringBuilder stringBuilder; 
            int counter = 1
 
            Session[this.sessionNoteKey] = notes; 
 
            XmlDocument xmlDoc = new XmlDocument(); 
            XmlElement notesBlock = xmlDoc.CreateElement("div"); 
            notesBlock.SetAttribute("class", "notesblock"); 
            xmlDoc.AppendChild(notesBlock); 
 
 
            stringBuilder = new StringBuilder("<div class=\"notesblock\">"); 
 
            stringBuilder.Append("<ol class=\"noteslist\">"); 
 
            stringBuilder.Append("<li>"); 
 
            notesHeader.Text = stringBuilder.ToString(); 
 
            xmlDoc = new XmlDocument(); 
            notesBlock = xmlDoc.CreateElement("div"); 
            notesBlock.SetAttribute("class", "notesblock"); 
            xmlDoc.AppendChild(notesBlock); 
 
 
            RadPanelBar1.Items.Clear(); 
 
            for (int i = 0; i < notes.Count; i++) 
            { 
                String userName = notes[i].Username; 
                String pendingStatus = " - Pending "
                String dateTime = notes[i].DateTime.ToShortDateString(); 
                String noteText = notes[i].Text.ToString(); 
                String newNote; 
 
                if (notes[i].Save == true) 
                { 
                    Session[tempNoteTextKey] = txtUserNote.Text; 
                    newNote = userName + pendingStatus + dateTime + " " + noteText; 
                     
                    txtUserNote.Text = notes[i].Text; 
                } 
 
                else 
                { 
                    CreateRPI(userName, dateTime, noteText); 
                } 
 
                counter++; 
            } 
 
 
            if (this.noteText.Length != 0) 
            { 
                return true; 
            } 
 
            return false; 
        } 
        #endregion 
 
        #region protected methods 
 
        protected void CancelButton_Click(object sender, EventArgs e) 
        { 
            txtUserNote.Text = string.Empty; 
            txtUserNote.Visible = false
            CancelButton.Visible = false
            SaveButton.Visible = false
        } 
 
 
        protected void SaveButton_Click(object sender, EventArgs e) 
        { 
            Note note; 
            CIS.Common.Business.Objects.InvoiceRouter.Notes notes; 
            bool isThereANewNote; 
 
            if (txtUserNote.Text.Length != 0) 
            { 
                notes = (Notes)Session[this.sessionNoteKey]; 
 
                isThereANewNote = false
 
                foreach(Note n in notes) { 
                    if (n.Save) 
                    { 
                        isThereANewNote = true
                        break; 
                    } 
                } 
 
                if (!isThereANewNote) 
                { 
                    note = new Note(); 
                    note.DateTime = System.DateTime.Now; 
                    if (Session[tempNoteTextKey] == null) 
                    { 
                        note.Text = txtUserNote.Text; 
                    } 
                    else 
                    { 
                        note.Text = Session[tempNoteTextKey].ToString(); 
                    } 
 
                    txtUserNote.Text = note.Text; 
                    note.Username = (Session[Key]).UserName.ToUpper(); 
                    note.Save = true
                    notes.Add(note); 
                } 
                else 
                { 
                    note = notes[notes.Count - 1]; 
                    note.DateTime = System.DateTime.Now; 
                    if (Session[tempNoteTextKey] == null) 
                    { 
                        note.Text = txtUserNote.Text; 
                    } 
                    else 
                    { 
                        note.Text = Session[tempNoteTextKey].ToString(); 
                    } 
 
                    txtUserNote.Text = note.Text; 
                     
                    note.Save = true;                     
                } 
                 
                LoadNoteHistory(notes); 
                 
            } 
            txtUserNote.Visible = true
            CancelButton.Visible = true
            SaveButton.Visible = true
        } 
 
        protected void txtUserNote_TextChanged(object sender, EventArgs e) 
        { 
            this.userNote = txtUserNote.Text; 
        } 
        #endregion 
 
        #region event handlers 
 
 
 
        #endregion 
 
        #region IPostBackDataHandler Members 
 
        public bool LoadPostData(string postDataKey, System.Collections.Specialized.NameValueCollection postCollection) 
        { 
            return true; 
        } 
 
        public void RaisePostDataChangedEvent() 
        { 
            //Not Implemented 
        } 
 
        #endregion 
 
        #region RadPanelItem Creation 
 
 
        RadPanelItem CreateRPI(String panelItemName1, String panelItemName2, String panelItems1) 
        { 
            RadPanelItem rpi = new RadPanelItem(); 
            rpi.Text = panelItemName1 + " " + panelItemName2; 
            rpi.Font.Size = 8
            RadPanelItem rpItem = new RadPanelItem(); 
            rpItem.Text = panelItems1
            rpItem.Font.Size = 8
            rpi.Items.Add(rpItem); 
            RadPanelBar1.Items.Add(rpi); 
            return rpi; 
        } 
 
        RadPanelItem CreateNewNote(String panelItemName1, String pendingItem, String panelItemName2, String panelItems1) 
        { 
            RadPanelItem rpi = new RadPanelItem(); 
            rpi.Text = panelItemName1 + pendingItem + panelItemName2; 
            rpi.Font.Size = 8
            RadPanelItem rpItem = new RadPanelItem(); 
            rpItem.Text = panelItems1
            rpItem.Font.Size = 8
            rpi.Items.Add(rpItem); 
            RadPanelBar1.Items.Add(rpi); 
            return rpi; 
        } 
         
 
 
        #endregion 
    } 
 
 
 

1 Answer, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 29 Oct 2009, 07:31 AM
Hi Lindsey,

I tried to reproduce the issue with the provided code but to no avail (I commented some code in order to run it).  How exactly you're using the user control on the page? Also could you please try not to load the panelbar on every postback like this:


if(!IsPostBack)
  LoadNoteHistory(notes);

Kind regards,
Yana
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
PanelBar
Asked by
Lindsey Kelly
Top achievements
Rank 1
Answers by
Yana
Telerik team
Share this question
or