Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Friends,

I am using RequiredFieldValidator to validate my asp.net controls. But I'm facing some weird problem because this is not going to happen in this case i did the same thing already in my another websites.

My aspx code is below:
XML
<asp:Panel ID="pnlRegister" runat="server" DefaultButton="btnRegister">
                <div class="form-group has-feedback lg left-feedback no-label">
                    <asp:TextBox ID="txtUsername" runat="server"
                        CssClass="form-control no-border input-lg" autofocus
                        placeholder="Choose Name" AutoComplete="off"
                        ValidationGroup="RegisterForm"></asp:TextBox>
                    <span class="fa fa-user form-control-feedback"></span>
                    <asp:RequiredFieldValidator ID="reqUsername" runat="server" ValidationGroup="RegisterForm"
                        ErrorMessage="Please enter Username." SetFocusOnError="true" Display="Dynamic"
                        ControlToValidate="txtUsername" ForeColor="#900900"></asp:RequiredFieldValidator>
                </div>
                <div class="form-group has-feedback lg left-feedback no-label">
                    <asp:TextBox ID="txtEmail" runat="server"
                        CssClass="form-control no-border input-lg"
                        placeholder="Enter email" AutoComplete="off"
                        ValidationGroup="RegisterForm"></asp:TextBox>
                    <span class="fa fa-envelope form-control-feedback"></span>
                    <asp:RequiredFieldValidator ID="reqEmail" runat="server" ValidationGroup="RegisterForm"
                        ErrorMessage="Please enter Email." SetFocusOnError="true" Display="Dynamic"
                        ControlToValidate="txtEmail" ForeColor="#900900"></asp:RequiredFieldValidator>
                    <asp:RegularExpressionValidator ID="regRegisterEmail" runat="server"
                        ErrorMessage="Invalid Email Address." ControlToValidate="txtEmail"
                        Display="Dynamic" SetFocusOnError="true" ForeColor="#900900"
                        ValidationGroup="RegisterForm"
                        ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">
                    </asp:RegularExpressionValidator>
                </div>
                <div class="form-group">
                    <asp:Button ID="btnRegister" runat="server" Text="Register"
                        ValidationGroup="RegisterForm"
                        CssClass="btn btn-warning btn-lg btn-perspective btn-block" />
                </div>
            </asp:Panel>


I am not using any JavaScript library or any other js file in this aspx page. I only have this form nothing else.

Please guyz help me. Thank you.
Posted
Updated 3-Jul-15 16:11pm
v3
Comments
Suvendu Shekhar Giri 3-Jul-15 23:02pm    
So what is that weired problem? Your code looks fine.
Jariwala Amin 4-Jul-15 2:25am    
ya its look fine but not working
harpreet.singh6771 4-Jul-15 1:41am    
Please Elaborate the problem
Jariwala Amin 4-Jul-15 2:33am    
That's all what I have. My page contain only this form which i have submitted here.
deepankarbhatnagar 4-Jul-15 3:16am    
Not getting, please explain... are you using on design page <%page... validaterequest=false>

please check ur controltovalidate property of validation..............
 
Share this answer
 
I found somthing guyz. When I remove my Gobal.asax file all validations are working properly!! I don't understand. I only have this in my Global.asax file.

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Routing;
using System.Web.Security;
using System.Web.SessionState;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using MyWebsite.Libraries.Global;

namespace MyWebsite.Website
{
    public class Global : System.Web.HttpApplication
    {

        protected void Application_Start(object sender, EventArgs e)
        {
            // Code that runs on application startup
            RegisterRoutes(RouteTable.Routes);
        }

        static void RegisterRoutes(RouteCollection routes)
        {
            // root pages
            routes.MapPageRoute("default", "", "~/default.aspx");
            routes.MapPageRoute("view", "view", "~/quick.aspx");
            routes.MapPageRoute("view/id", "view/{id}", "~/quick.aspx");
            routes.MapPageRoute("slug", "{slug}", "~/page.aspx");
            routes.MapPageRoute("contact-us", "contact-us", "~/contact-us.aspx");
        }

        protected void Session_Start(object sender, EventArgs e)
        {

        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {

        }

        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {

        }

        protected void Application_Error(object sender, EventArgs e)
        {

        }

        protected void Session_End(object sender, EventArgs e)
        {

        }

        protected void Application_End(object sender, EventArgs e)
        {

        }
    }
}
 
Share this answer
 

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