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

[Solved] Blocking special charectore in grid filter

4 Answers 128 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sharon
Top achievements
Rank 2
Sharon asked on 14 Jan 2010, 06:54 AM
hi

Could some one tell me how to block the filtering of special charetors ina grid

In my application, the grid has a filter colomn when i type special charectore in the filter and select "Equal to" i am geting the following error.
Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: Requested value '[]:"' was not found.

could you tell me how to handle this

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 14 Jan 2010, 07:22 AM
Hello Sharon

Check out the following code to avoid filtering using special characters:
C#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) 
    if (e.Item is GridFilteringItem) 
    { 
        GridFilteringItem filterItem = (GridFilteringItem)e.Item; 
        foreach (GridColumn col in RadGrid1.MasterTableView.Columns) 
        { 
            (filterItem[col.UniqueName].Controls[0] as TextBox).Attributes.Add("onkeyup""CharacterCheck(this, event)"); 
        } 
    } 

JavaScript:
<script type="text/javascript">  
function CharacterCheck(text,e)  
{  
    var regx, flg;    
    regx = /[^0-9a-zA-Z'' ]/    
    flg = regx.test(text.value);    
    if (flg)  
    {    
        var val=text.value;  
        val=val.substr(0,(val.length)-1)  
        text.value=val;        
    }    
}  
</script>  

Hope this helps..
Princy.
0
Sharon
Top achievements
Rank 2
answered on 14 Jan 2010, 08:56 AM
Hi princy
its still not working

Actually i am using filtering only for two fields in the grid so i have made some changes to the code u send me but thats also not working

the change i made are
protected void gvDigProperty_ItemCreated(object sender, GridItemEventArgs e)  
    {  
        if (e.Item is GridFilteringItem)  
        {  
            GridFilteringItem filterItem = (GridFilteringItem)e.Item;  
            foreach (GridColumn col in gvDigProperty.MasterTableView.Columns)  
            {  
                (filterItem["Propertytype"].Controls[0] as TextBox).Attributes.Add("onkeyup""CharacterCheck(this, event)");  
                (filterItem["PRO_AMT_WORTH"].Controls[0] as TextBox).Attributes.Add("onkeyup""CharacterCheck(this, event)");  
            }  
        }    
 
    } 
 i have not made any changes to the JScript you send me
function CharacterCheck(text, e) {  
            var regx, flg;  
            regx = /[^0-9a-zA-Z'' ]/  
            flg = regx.test(text.value);  
            if (flg) {  
                var val = text.value;  
                val = val.substr(0, (val.length) - 1)  
                text.value = val;  
            }  
        }    

do u have any other suggestion

0
Mira
Telerik team
answered on 19 Jan 2010, 07:35 AM
Hello Sharon,

I have followed your scenario and prepared a sample project for you using the code Princy suggested.

I hope you will find it useful.

Kind regards,
Mira
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.
0
Sharon
Top achievements
Rank 2
answered on 19 Jan 2010, 09:10 AM
hi Mira
thank you for your reply

regards
Sharon
Tags
Grid
Asked by
Sharon
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 2
Sharon
Top achievements
Rank 2
Mira
Telerik team
Share this question
or