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

[Solved] MaxLength is not working

10 Answers 375 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Anto (DLL Version : 2008.3.1314.35)
Top achievements
Rank 2
Anto (DLL Version : 2008.3.1314.35) asked on 06 Jul 2009, 11:37 AM
Hi All

Have a radgrid with datas. it works properly.

with a issue.

Issue is:

The MaxLength does not works.

My Code:

<

telerik:GridTemplateColumn UniqueName="Description" DataField="Description" HeaderText="Description">  

 

<ItemTemplate 

 

<asp:TextBox ID="txtDescription1" Columns="15" MaxLength="255" Rows="2" TextMode="MultiLine" Text='<%#Bind("Description")%>'

 

runat="server" ReadOnly="true" ></asp:TextBox 

 

</ItemTemplate 

 

<EditItemTemplate 

 

<asp:TextBox ID="txtDescription" Columns="25" MaxLength="255" Rows="5" TextMode="MultiLine" Text='<%#Bind("Description")%>'

 

runat="server"></asp:TextBox 

 

<asp:RequiredFieldValidator ID="RequiredFieldValidatorDescription" runat="server" ErrorMessage="*"

 

ControlToValidate="txtDescription"></asp:RequiredFieldValidator>  

 

 

</EditItemTemplate 

 

</telerik:GridTemplateColumn>


I have set the MaxLendth to 255, But it not working

Thank You

-Anto

 

 

10 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 06 Jul 2009, 12:21 PM
Hello Anto,

It seems when the TextBox is set to MultiLine mode then the MaxLength propertywill not work. Instead you can use javascript code for validating the enteredcharacters. Check out the following for reference:

Restrict number of characters to be entered in the MultiLine TextBox

Thanks

Shinu.


0
Anto (DLL Version : 2008.3.1314.35)
Top achievements
Rank 2
answered on 06 Jul 2009, 12:56 PM
Hi Shinu,

The link you send me, is for a textbox which is not inside a grid.

It doesn't work in the GridTemplateColumn.

So please can you send me any other option that works in a grid.
 
Thank You

-Anto

0
Anto (DLL Version : 2008.3.1314.35)
Top achievements
Rank 2
answered on 07 Jul 2009, 04:43 AM
Hi Shinu

It's not working.

-Anto
0
Accepted
Daniel
Telerik team
answered on 07 Jul 2009, 06:00 AM
Hello Anto,

To avoid such limitations we recommend you use RadControls - namely the RadTextBox:
<telerik:RadTextBox  
    ID="RadTextBox1"  
    runat="server"  
    TextMode="MultiLine"  
    MaxLength="5" /> 

Regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Princy
Top achievements
Rank 2
answered on 07 Jul 2009, 06:17 AM
Hello Anto,

You can restrict the length of the Textboxes using server code as shown below:
c#:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem) 
        { 
            GridDataItem dataItem = (GridDataItem)e.Item; 
            TextBox txtbx = (TextBox)dataItem.FindControl("txtDescription1"); 
            string strtxt = txtbx.Text; 
            if (strtxt.Length > 255) 
            { 
                txtbx.Text = strtxt.Remove(255); 
            }          
        } 
        if (e.Item is GridEditableItem && e.Item.IsInEditMode) 
        { 
            GridEditableItem editItem = (GridEditableItem)e.Item; 
            TextBox txtbx1 = (TextBox)editItem.FindControl("txtDescription"); 
            string strtxt1 = txtbx1.Text; 
            if (strtxt1.Length > 255) 
            { 
                txtbx1.Text = strtxt1.Remove(255); 
            } 
        } 
  } 

Thanks
Princy.
0
Leo
Top achievements
Rank 1
answered on 07 Jul 2009, 07:57 AM
It works
0
Anto (DLL Version : 2008.3.1314.35)
Top achievements
Rank 2
answered on 07 Jul 2009, 08:01 AM
Hi Daniel,

Thank You for ur reply

I have given radtextbox, it works.

But scrolling appears. Is there any option to avoid it.

-Anto
0
Accepted
Daniel
Telerik team
answered on 07 Jul 2009, 08:13 AM
Hello Anto,

It is possible to set overflow:hidden to avoid the scrollbars:
<telerik:RadTextBox  
   ID="RadTextBox2"  
   runat="server"  
   TextMode="MultiLine" 
   MaxLength="255"  
   style="overflow:hidden" /> 

Regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Anto (DLL Version : 2008.3.1314.35)
Top achievements
Rank 2
answered on 07 Jul 2009, 09:57 AM
Hi Daniel

Thank You very much.

It works properly.

-Anto
0
Anto (DLL Version : 2008.3.1314.35)
Top achievements
Rank 2
answered on 07 Jul 2009, 10:01 AM
Hi Princy,

Went for the method given by Daniel.

It works without any problem.

Eventhough thank you for your reply.

-Anto
Tags
Grid
Asked by
Anto (DLL Version : 2008.3.1314.35)
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 2
Anto (DLL Version : 2008.3.1314.35)
Top achievements
Rank 2
Daniel
Telerik team
Princy
Top achievements
Rank 2
Leo
Top achievements
Rank 1
Share this question
or