Hi. I need to store my validation expression strings in the
web.config file. For URL validation, I have the following code in my
aspx file:
<asp:TextBox ID="txtRedirectUrl" runat="server" />
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" ControlToValidate="txtRedirectUrl" Display="dynamic"
Text="Please enter a valid URL" ValidationExpression='<%#
WebConfigurationManager.AppSettings["UrlValExpression"] %>'
runat="server" />
My web.config entry looks like this:
<appSettings>
<add key="UrlValExpression" value="
(http(s)?://)([\w-]+\.)+[\w-]+(/[\w-
./?%&=]*)?|([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)? "
/>
</appSettings>
For whatever
reason, it's not working. Nothing passes validation; not even valid
URL's. Then the app is stuck on the page; i.e., I cannot backspace out
the text and try again. I have to do a postback in order to attempt
the validation again.
I need to be able to retrieve the validation expression from the aspx page, and not the code behind file. Thanks for the help.