Click here to Skip to main content
15,917,061 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
It is possible to Call a value from webconfig to Regular Expression Validator Expression.

I had tried this

<asp:RegularExpressionValidator runat="server" ID="RegularExpressionFileUpload" ControlToValidate="FileUploadControl" ErrorMessage="Image Files Only (.jpg, .bmp, .png, .gif)" SetFocusOnError="true"  ValidationExpression=<%RegularExpression %> />


code behind
Protected String RegularExpressionVal="/^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))+(.jpeg|.JPEG|.gif|.GIF|.png|.PNG|.JPG|.jpg|.bitmap|.BITMAP)$/"


Give Suggestion to get a solution.

Thanks in Advance.
Posted

1 solution

That should be like...
ASP.NET
<asp:RegularExpressionValidator runat="server" ID="RegularExpressionFileUpload" ControlToValidate="FileUploadControl" ErrorMessage="Image Files Only (.jpg, .bmp, .png, .gif)" SetFocusOnError="true"  ValidationExpression='<%#RegularExpressionVal %>' />

And the variable in code behind...
C#
public string RegularExpressionVal="/^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))+(.jpeg|.JPEG|.gif|.GIF|.png|.PNG|.JPG|.jpg|.bitmap|.BITMAP)$/";


But I don't understand this approach, because you can directly define this in aspx page.
 
Share this answer
 
Comments
[no name] 19-May-14 3:16am    
<
But I don't understand this approach, because you can directly define this in aspx
>

 <br><br>
Because the Expression can be change during run time.thats why i want to get a expression from webconfig.
FYI
this did not working.
Go to the Source HTML in Browser and locate this validator. See what is the expression bind with it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900