ASP.NET RequiredField RegularExpression Triggering After Page Postback

Last Reply 5 months ago By pandeyism

Posted 5 months ago

Sir,

In my registration i am having around 10 fields as textbox dropdownlist and fileupload and also a submit button. When I click on submit button the validations are not triggering also page is posting back and then validations getting triggered. why.

I have used Master page and used Toolscriptmanager for ajax calendar.

Results 1 - 5 of 9 12

Posted 5 months ago

html: 

<%@ Master Language="VB" CodeFile="userPanelMasterPage.master.vb" Inherits="userPanelMasterPage" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Directorate of School Education Jammu</title>
	<script type="text/javascript" language="javascript">
	    history.forward(1);
    </script>
	<link href="css/style.css" rel="stylesheet" type="text/css" />
	<link rel="stylesheet" href="css/font-awesome.min.css"/>
    <asp:ContentPlaceHolder ID="contentPlaceHolderHead" runat="server"></asp:ContentPlaceHolder>
  </head>
  <body class="bodyfontstyle">
    <form id="Form1" runat="server" autocomplete="off">
      <table width="100%" cellpadding="0" cellspacing="0">
	   <tr>
	      <td height="7" class="bluecolor"></td>
	   </tr>
	   <tr>
	      <td class="banner" align="center"><table width="1200"><tr><td><h1 class="bannertitle">Directorate Of School Education Jammu</h1></td></tr></table></td>
	   </tr>
          <tr>
              <td align="center">
                  <table width="1200">
                      <tr>
                          <td align="right"><asp:LinkButton ID="LinkButton1" runat="server" PostBackUrl="~/index.aspx" CssClass="fa fa-sign-out signout">&nbsp;Sign Out</asp:LinkButton></td>
                      </tr>
                  </table>
              </td>
          </tr>
	   <tr>
	      <td align="center" class="bodypage" valign="top">
              <asp:ContentPlaceHolder ID="contentPlaceHolderBody" runat="server"></asp:ContentPlaceHolder>
		  </td>
	   </tr>
	   <tr>
	      <td class="footerclass" align="center">
		   <span>Website designed &amp; developed by National Informatics Center.</span>
		  </td>
	   </tr>
	 </table>
          </form>
  </body>
</html>

vb: 

Imports System.Data.SqlClient

Partial Class user_panel
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
        If Request.UrlReferrer = Nothing Then
            Response.Redirect("index.aspx", True)
            Exit Sub
        End If
        If Session("sponsor") = Nothing Then
            Response.Redirect("index.aspx", True)
            Exit Sub
        End If
        If Session("school") = Nothing Then
            Response.Redirect("index.aspx", True)
            Exit Sub
        End If
        If Session("mobile") = Nothing Then
            Response.Redirect("index.aspx", True)
            Exit Sub
        End If
        If Not Page.IsPostBack Then
            lbloggedin.Text = Session("sponsor") & "&nbsp;<strong>|</strong>&nbsp;" & Session("school") & "&nbsp;<strong>|</strong>&nbsp;" & Session("mobile")
            textboxsponsorname.Text = Session("sponsor")
            textboxschoolname.Text = Session("school")
            textboxcontactno.Text = Session("mobile")
            loadclassrecog()
        End If
    End Sub

    Sub loadclassrecog()
        Dim i As Integer = 0
        dropdownclassrecoganized.Items.Clear()
        dropdownclassrecoganized.Items.Add("--Select--")
        dropdownclassrecoganized.Items(i).Value = 0
        Using con As New SqlConnection(ConfigurationManager.ConnectionStrings("dsejConnectionString").ConnectionString)
            Using cmd As New SqlCommand("Select * from class_master", con)
                con.Open()
                Dim dr As SqlDataReader = cmd.ExecuteReader
                While dr.Read
                    i += 1
                    dropdownclassrecoganized.Items.Add(dr("classname"))
                    dropdownclassrecoganized.Items(i).Value = dr("id")
                End While
                con.Close()
            End Using
        End Using
    End Sub

    Protected Sub RadioButtonList1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles RadioButtonList1.SelectedIndexChanged
        If RadioButtonList1.SelectedIndex = -1 Then
            ScriptManager.RegisterStartupScript(Me, Page.GetType, "Script", "msgbox('You Must Select Affiliation Before Proceed');", True)
            Exit Sub
        ElseIf RadioButtonList1.SelectedIndex <> -1 Then
            panelAffliationType.Visible = True
            Exit Sub
        End If
    End Sub

    Protected Sub radiobuttonMC_SelectedIndexChanged(sender As Object, e As EventArgs) Handles radiobuttonMC.SelectedIndexChanged
        If radiobuttonMC.SelectedIndex = 0 Then
            paneluploadmc.Visible = True
        Else
            paneluploadmc.Visible = False
        End If
    End Sub

    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim estddate As Date = Convert.ToDateTime(textboxestablishment.Text.Trim())
        If estddate >= Now.Date Then
            ScriptManager.RegisterStartupScript(Me, Page.GetType, "Script", "msgbox('Date of establishment should be less than current date.');", True)
            Exit Sub
        End If
    End Sub

    Protected Sub Page_Init(sender As Object, e As EventArgs) Handles Me.Init
        If Not Me.Page.EnableViewStateMac Then
            Throw New InvalidOperationException("The page does NOT have the MAC enabled and the viewstate is therefore vulnerable to tampering.")
        End If

        Me.ViewStateUserKey = Me.Session.SessionID
    End Sub
End Class

 Web.Config:

<pages controlRenderingCompatibilityVersion="4.0" clientIDMode="AutoID" enableViewStateMac="true">

 



Posted 5 months ago

user_panel

<%@ Page Title="" Language="VB" MasterPageFile="~/userPanelMasterPage.master" AutoEventWireup="false" CodeFile="user_panel.aspx.vb" Inherits="register" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>

<asp:Content ID="Content1" ContentPlaceHolderID="contentPlaceHolderHead" runat="Server">
    <script>
        function msgbox(m) {
            alert(m);
        }

    </script>

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="contentPlaceHolderBody" runat="Server">
    <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></asp:ToolkitScriptManager>
    <table width="1200">
        <tr>
            <td align="left" valign="middle">
                <h1>
                    <div class="pageheader"><span><i class="fa fa-pencil-square"></i>&nbsp;User Panel</div>
                    <div class="notes">
                        <asp:Label ID="lbloggedin" runat="server" Text=""></asp:Label>
                    </div>
                </h1>
            </td>
        </tr>

        <%--<tr>
            <td align="center">
                <asp:Label ID="lblmsg" runat="server" Text="" CssClass="messages"></asp:Label>
            </td>
        </tr>--%>
        <tr>
            <td height="15"></td>
        </tr>
        <tr>
            <td align="center" valign="top">


                <table width="300">
                    <tr>
                        <td align="left" valign="middle">
                            <div class="formtext">Affiliation To<span class="mandatory"> *</span></div>


                        </td>
                        <td align="left" valign="middle">
                            <asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatDirection="Horizontal" AutoPostBack="True">
                                <asp:ListItem Value="J">JKBOSE</asp:ListItem>
                                <asp:ListItem Value="C">CBSE</asp:ListItem>
                            </asp:RadioButtonList>
                        </td>
                    </tr>
                </table>

            </td>
        </tr>
        <tr>
            <td align="center">
                <asp:Panel ID="panelAffliationType" runat="server" Visible="false">
                    <table width="100%">
                        <tr>
                            <td align="center" valign="top">
                                <asp:Menu ID="Menu1" StaticMenuItemStyle-CssClass="tab" StaticSelectedStyle-CssClass="selectedtab" CssClass="tabs" runat="server" Orientation="Horizontal" StaticSubMenuIndent="16px">
                                    <Items>
                                        <asp:MenuItem Text="Basic School Details" Value="0" Selected="true"></asp:MenuItem>
                                        <asp:MenuItem Text="Infrastructure" Value="1" Enabled="false"></asp:MenuItem>
                                        <asp:MenuItem Text="Room Dimensions" Value="2" Enabled="false"></asp:MenuItem>
                                        <asp:MenuItem Text="Total Rooms & Sizes" Value="3" Enabled="false"></asp:MenuItem>
                                        <asp:MenuItem Text="Facilities" Value="4" Enabled="false"></asp:MenuItem>
                                        <asp:MenuItem Text="Staff" Value="5" Enabled="false"></asp:MenuItem>
                                        <asp:MenuItem Text="Students Enrolled" Value="6" Enabled="false"></asp:MenuItem>
                                        <asp:MenuItem Text="Fee Details" Value="7" Enabled="false"></asp:MenuItem>
                                        <asp:MenuItem Text="Final Submission" Value="8" Enabled="false"></asp:MenuItem>
                                    </Items>
                                </asp:Menu>
                                <div class="tabcontents">
                                    <br />
                                    <center><asp:Label ID="lblmsg" runat="server" forecolor="red"></asp:Label></center>
                                    <br />
                                    <asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0">
                                        <asp:View ID="View1" runat="server">
                                            <center>
                                                <div id="tablelayout">
                                                   <table width="100%">
                                                       <tr>
                                                           <td align="left" valign="top" width="25%">
                                                               <div class="formtext">Name of the school<span class="mandatory"> *</span></div>
                                                               <asp:TextBox ID="textboxschoolname" runat="server" MaxLength="50" autocomplete="off" Enabled="false"></asp:TextBox>
                                                                
                                                               <asp:RequiredFieldValidator ID="RequiredFieldValidatortextboxschoolname" runat="server" ControlToValidate="textboxschoolname" ErrorMessage="*Required" cssClass="errmsg" ValidationGroup="tab1" Display="Dynamic" SetFocusOnError="True"></asp:RequiredFieldValidator>
                                                               <asp:RegularExpressionValidator ValidationGroup="tab1" CssClass="errmsg" Display="Dynamic" SetFocusOnError="true" ID="RegularExpressionValidator1textboxschoolname" ControlToValidate="textboxschoolname" runat="server" ErrorMessage="Only alphabets & space Max. 50 chars" ValidationExpression="[a-zA-Z ]{1,50}$"></asp:RegularExpressionValidator>
                                                           </td>
                                                           <td align="left" valign="top" width="25%">
                                                               <div class="formtext">Name of sponsor/propreitor<span class="mandatory"> *</span></div>
                                                               <asp:TextBox ID="textboxsponsorname" runat="server" MaxLength="10" autocomplete="off"  Enabled="false"></asp:TextBox>
                                                                
                                                               <asp:RequiredFieldValidator ID="RequiredFieldValidator1textboxsponsorname" runat="server" ControlToValidate="textboxsponsorname" ErrorMessage="*Required" cssClass="errmsg" ValidationGroup="tab1" Display="Dynamic" SetFocusOnError="True"></asp:RequiredFieldValidator>
                                                               <asp:RegularExpressionValidator ValidationGroup="tab1" CssClass="errmsg" Display="Dynamic" SetFocusOnError="true" ID="RegularExpressionValidator1textboxsponsorname" ControlToValidate="textboxsponsorname" runat="server" ErrorMessage="Only alphabets & space Max. 30 chars" ValidationExpression="[a-zA-Z ]{1,30}$"></asp:RegularExpressionValidator>
                                                           </td> 
                                                           <td align="left" valign="top" width="25%">

                                                               <div class="formtext">Contact No<span class="mandatory"> *</span></div>
                                                               <asp:TextBox ID="textboxcontactno" runat="server" MaxLength="10" autocomplete="off"  Enabled="false"></asp:TextBox>
                                                               <asp:RequiredFieldValidator ID="RequiredFieldValidator1textboxcontactno" runat="server" ControlToValidate="textboxcontactno" ErrorMessage="*Required" cssClass="errmsg" ValidationGroup="tab1" Display="Dynamic" SetFocusOnError="True"></asp:RequiredFieldValidator>
                                                               <asp:RegularExpressionValidator ValidationGroup="tab1" CssClass="errmsg" Display="Dynamic" SetFocusOnError="true" ID="RegularExpressionValidator1textboxcontactno" ControlToValidate="textboxcontactno" runat="server" ErrorMessage="Should be 10 digit mobile no" ValidationExpression="^[0-9]{10}$"></asp:RegularExpressionValidator>
                                                           </td>
                                                           <td align="left" valign="top" width="25%">
                                                               
                                                               <div class="formtext">Date of Establishment<span class="mandatory"> *</span></div>
                                                               <asp:TextBox ID="textboxestablishment" runat="server" MaxLength="11" autocomplete="off" placeholder="dd-MMM-yyyy"></asp:TextBox>
                                                               <asp:CalendarExtender ID="CalendarExtender8textboxestablishment" PopupButtonID="imgPopup" runat="server" TargetControlID="textboxestablishment" Format="dd-MMM-yyyy"></asp:CalendarExtender>
                                                               <asp:RequiredFieldValidator ID="RequiredFieldValidator1textboxestablishment" runat="server" ControlToValidate="textboxestablishment" ErrorMessage="*Required" cssClass="errmsg" ValidationGroup="tab1" Display="Dynamic" SetFocusOnError="True"></asp:RequiredFieldValidator>
                                                               <asp:RegularExpressionValidator ValidationGroup="tab1" CssClass="errmsg" Display="Dynamic" SetFocusOnError="true" ID="RegularExpressionValidator1textboxestablishment" ControlToValidate="textboxestablishment" runat="server" ErrorMessage="Format should be dd-mmm-yyyy" ValidationExpression="^(([0-9])|([0-2][0-9])|([3][0-1]))\-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\-\d{4}$"></asp:RegularExpressionValidator>
                                                           </td>
                                                       </tr>
                                                       <tr>
                                                           <td align="left" valign="top">
                                                               <div class="formtext">Email address<span class="mandatory"> *</span></div>
                                                               <asp:TextBox ID="textboxemailaddress" runat="server" MaxLength="50" autocomplete="off"></asp:TextBox>
                                                               <asp:RequiredFieldValidator ID="RequiredFieldValidator1textboxemailaddress" runat="server" ControlToValidate="textboxemailaddress" ErrorMessage="*Required" cssClass="errmsg" ValidationGroup="tab1" Display="Dynamic" SetFocusOnError="True"></asp:RequiredFieldValidator>
                                                               <asp:RegularExpressionValidator ValidationGroup="tab1" CssClass="errmsg" Display="Dynamic" SetFocusOnError="true" ID="RegularExpressionValidator1textboxemailaddress" ControlToValidate="textboxemailaddress" runat="server" ErrorMessage="Email address not valid" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
                                                           </td>
                                                           <td align="left" valign="top">
                                                               <div class="formtext">Address<span class="mandatory"> *</span></div>
                                                               <asp:TextBox ID="textboxaddress" runat="server" MaxLength="300" Height="50px" autocomplete="off" TextMode="MultiLine"></asp:TextBox>
                                                               <asp:RequiredFieldValidator ID="RequiredFieldValidator1textboxaddress" runat="server" ControlToValidate="textboxaddress" ErrorMessage="*Required" cssClass="errmsg" ValidationGroup="tab1" Display="Dynamic" SetFocusOnError="True"></asp:RequiredFieldValidator>
                                                               <asp:RegularExpressionValidator ValidationGroup="tab1" CssClass="errmsg" Display="Dynamic" SetFocusOnError="true" ID="RegularExpressionValidator1textboxaddress" ControlToValidate="textboxaddress" runat="server" ErrorMessage="Should be alphabets & space Max. 300 chars" ValidationExpression="[a-zA-Z0-9 ]{1,300}$"></asp:RegularExpressionValidator>
                                                           </td> 
                                                           <td align="left" valign="top">
                                                               <div class="formtext">Principal Name<span class="mandatory"> *</span></div>
                                                               <asp:TextBox ID="textboxprincipalname" runat="server" MaxLength="30" autocomplete="off"></asp:TextBox>
                                                               <asp:RequiredFieldValidator ID="RequiredFieldValidator1textboxprincipalname" runat="server" ControlToValidate="textboxprincipalname" ErrorMessage="*Required" cssClass="errmsg" ValidationGroup="tab1" Display="Dynamic" SetFocusOnError="True"></asp:RequiredFieldValidator>
                                                               <asp:RegularExpressionValidator ValidationGroup="tab1" CssClass="errmsg" Display="Dynamic" SetFocusOnError="true" ID="RegularExpressionValidator1textboxprincipalname" ControlToValidate="textboxprincipalname" runat="server" ErrorMessage="Should be alphabets & space Max. 30 chars" ValidationExpression="[a-zA-Z ]{1,30}$"></asp:RegularExpressionValidator>
                                                           </td>
                                                           <td align="left" valign="top">
                                                               <div class="formtext">Principal Qualification<span class="mandatory"> *</span></div>
                                                               <asp:TextBox ID="textboxprincipalqualification" runat="server" MaxLength="50" autocomplete="off"></asp:TextBox>
                                                               <asp:RequiredFieldValidator ID="RequiredFieldValidator1textboxprincipalqualification" runat="server" ControlToValidate="textboxprincipalqualification" ErrorMessage="*Required" cssClass="errmsg" ValidationGroup="tab1" Display="Dynamic" SetFocusOnError="True"></asp:RequiredFieldValidator>
                                                               <asp:RegularExpressionValidator ValidationGroup="tab1" CssClass="errmsg" Display="Dynamic" SetFocusOnError="true" ID="RegularExpressionValidator1textboxprincipalqualification" ControlToValidate="textboxprincipalqualification" runat="server" ErrorMessage="Can be comma separated values Max. 100 chars" ValidationExpression="[a-zA-Z, ]{1,100}$"></asp:RegularExpressionValidator>
                                                           </td>
                                                       </tr>
                                                       <tr>
                                                           <td align="left" valign="top">
                                                               <div class="formtext">Date and Order No. of Affliation/ Recognition<span class="mandatory"> *</span></div>
                                                               <asp:TextBox ID="textboxdoa" runat="server" MaxLength="11" autocomplete="off" Width="120px" placeholder="dd-MMM-yyyy"></asp:TextBox>&nbsp;
                                                               <asp:TextBox ID="textboxorderno" runat="server" MaxLength="10" Width="100px" autocomplete="off" placeholder="Order No."></asp:TextBox>
                                                               <asp:CalendarExtender ID="CalendarExtender1textboxdoa" PopupButtonID="imgPopup" runat="server" TargetControlID="textboxdoa" Format="dd-MMM-yyyy"></asp:CalendarExtender>
                                                               <asp:RequiredFieldValidator ID="RequiredFieldValidator1textboxdoa" runat="server" ControlToValidate="textboxdoa" ErrorMessage="*Select date" cssClass="errmsg" ValidationGroup="tab1" Display="Dynamic" SetFocusOnError="True"></asp:RequiredFieldValidator>
                                                               <asp:RequiredFieldValidator ID="RequiredFieldValidator1textboxorderno" runat="server" ControlToValidate="textboxorderno" ErrorMessage="*Enter order no" cssClass="errmsg" ValidationGroup="tab1" Display="Dynamic" SetFocusOnError="True"></asp:RequiredFieldValidator>
                                                               <asp:RegularExpressionValidator ValidationGroup="tab1" CssClass="errmsg" Display="Dynamic" SetFocusOnError="true" ID="RegularExpressionValidator1textboxdoa" ControlToValidate="textboxdoa" runat="server" ErrorMessage="Date format should be dd-mmm-yyyy" ValidationExpression="^(([0-9])|([0-2][0-9])|([3][0-1]))\-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\-\d{4}$"></asp:RegularExpressionValidator>
                                                           </td>
                                                           <td align="left" valign="top">
                                                               <div class="formtext">Order Valid upto<span class="mandatory"> *</span></div>
                                                               <asp:TextBox ID="textboxordervalidupto" runat="server" MaxLength="11" autocomplete="off" placeholder="dd-MMM-yyyy"></asp:TextBox><br />
                                                               <asp:CalendarExtender ID="CalendarExtender1textboxordervalidupto" PopupButtonID="imgPopup" runat="server" TargetControlID="textboxordervalidupto" Format="dd-MMM-yyyy"></asp:CalendarExtender>
                                                               <asp:RequiredFieldValidator ID="RequiredFieldValidator1textboxordervalidupto" runat="server" ControlToValidate="textboxordervalidupto" ErrorMessage="*Requied" cssClass="errmsg" ValidationGroup="tab1" Display="Dynamic" SetFocusOnError="True"></asp:RequiredFieldValidator>
                                                               <asp:RegularExpressionValidator ValidationGroup="tab1" CssClass="errmsg" Display="Dynamic" SetFocusOnError="true" ID="RegularExpressionValidator1textboxordervalidupto" ControlToValidate="textboxordervalidupto" runat="server" ErrorMessage="Date format should be dd-mmm-yyyy" ValidationExpression="^(([0-9])|([0-2][0-9])|([3][0-1]))\-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\-\d{4}$"></asp:RegularExpressionValidator>
                                                           </td>
                                                           <td align="left" valign="top">
                                                               <div class="formtext">Class upto which school is Recogrnized/ Affiliated(JKBOSE/CBSE)<span class="mandatory"> *</span></div>
                                                               <asp:DropDownList ID="dropdownclassrecoganized" runat="server"></asp:DropDownList>
                                                               <asp:RequiredFieldValidator ID="RequiredFieldValidator1dropdownclassrecoganized" InitialValue="0" runat="server" ControlToValidate="dropdownclassrecoganized" ErrorMessage="*Required" cssClass="errmsg" ValidationGroup="tab1" Display="Dynamic" SetFocusOnError="True"></asp:RequiredFieldValidator>
                                                               
                                                           </td>
                                                           <td align="left" valign="top">
                                                               <div class="formtext">Whether MC Approved?<span class="mandatory"> *</span></div>
                                                               <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                                                                   <ContentTemplate>
                                                                       <asp:RadioButtonList ID="radiobuttonMC" runat="server" RepeatDirection="Horizontal" AutoPostBack="true">
                                                                   <asp:ListItem Value="Y">Yes</asp:ListItem>
                                                                   <asp:ListItem Value="N">No</asp:ListItem>
                                                               </asp:RadioButtonList>
                                                                       <asp:Panel ID="paneluploadmc" runat="server" Visible="false" CssClass="margup">
                                                               <asp:FileUpload ID="fileuploadmc" runat="server" class="inputfile"></asp:FileUpload>
                                                               <label for="ctl00_contentPlaceHolderBody_fileuploadmc" class="selectlabel" id="fileuploadlabel">Select .jpg file</label>
                                                               <asp:RequiredFieldValidator ID="RequiredFieldValidator1fileuploadmc" runat="server" ControlToValidate="fileuploadmc" ErrorMessage="*Select file" cssClass="errmsg" ValidationGroup="tab1" Display="Dynamic" SetFocusOnError="True"></asp:RequiredFieldValidator>
                                                               <asp:RegularExpressionValidator ValidationGroup="tab1" CssClass="errmsg" Display="Dynamic" SetFocusOnError="true" ID="RegularExpressionValidator1fileuploadmc" ControlToValidate="fileuploadmc" runat="server" ErrorMessage="Should be .jpg only" ValidationExpression="([a-zA-Z0-9\s_\\.\-:])+(.jpg|.JPG)$"></asp:RegularExpressionValidator>
                                                                           </asp:Panel>
                                                                   </ContentTemplate>
                                                                   <Triggers>
                                                                       <asp:AsyncPostBackTrigger ControlID="radiobuttonMC" EventName="SelectedIndexChanged" />
                                                                   </Triggers>
                                                               </asp:UpdatePanel>
                                                           </td>
                                                       </tr>
                                                       <tr>
                                                           <td align="left" valign="top" colspan="4">
                                                               <div class="formtext">Books being taught in school<span class="mandatory"> *</span></div>
                                                               <asp:RadioButtonList ID="radiobuttonbooks" runat="server" RepeatDirection="Horizontal">
                                                                   <asp:ListItem Value="J">BOSE</asp:ListItem>
                                                                   <asp:ListItem Value="C">CBSE</asp:ListItem>
                                                                   <asp:ListItem Value="O">Others</asp:ListItem>
                                                               </asp:RadioButtonList>
                                                               <asp:RequiredFieldValidator ID="RequiredFieldValidator1radiobuttonbooks" runat="server" ControlToValidate="radiobuttonbooks" ErrorMessage="*Required" cssClass="errmsg" ValidationGroup="tab1" Display="Dynamic" SetFocusOnError="True"></asp:RequiredFieldValidator>
                                                           </td>
                                                       </tr>
                                                       <tr>
                                                           <td align="center" valign="top" colspan="4" bgcolor="#ececec">
                                                               <asp:Button ID="Button1" runat="server" Text="Submit" ValidationGroup="tab1" CssClass="submitbutton" OnClientClick="return confirm('Are you sure?');"></asp:Button>
                                                           </td>
                                                       </tr>
                                                   </table>
                                                </div>
                                            </center>
                                        </asp:View>
                                        <asp:View ID="View2" runat="server">
                                            <center>

                                            </center>
                                        </asp:View>
                                        <asp:View ID="View3" runat="server">
                                            <center>

                                            </center>
                                        </asp:View>
                                        <asp:View ID="View4" runat="server">
                                            <center>

                                            </center>
                                        </asp:View>
                                        <asp:View ID="View5" runat="server">
                                            <center>

                                            </center>
                                        </asp:View>
                                        <asp:View ID="View6" runat="server">
                                            <center>

                                            </center>
                                        </asp:View>
                                        <asp:View ID="View7" runat="server">
                                            <center>

                                            </center>
                                        </asp:View>
                                        <asp:View ID="View8" runat="server">
                                            <center>

                                            </center>
                                        </asp:View>
                                    </asp:MultiView>
                                </div>
                            </td>
                        </tr>
                    </table>
                </asp:Panel>
            </td>
        </tr>
        <tr>
            <td height="15"></td>
        </tr>
    </table>
</asp:Content>

 


Posted 5 months ago Modified on 5 months ago

Hi  Sumeet,

I checke your code is validation for all control except dropdowlist. so for validation dropdownlist replcae below code with your code.

You need to add below line of code.

dropdownclassrecoganized.Items.Add(New ListItem("--Select--", "0"))

Code

Public Sub loadclassrecog()
    Dim i As Integer = 0
    dropdownclassrecoganized.Items.Clear()
    dropdownclassrecoganized.Items.Add(New ListItem("--Select--", "0"))
    Using con As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("constr").ConnectionString)
        Using cmd As SqlCommand = New SqlCommand("Select * from Customers", con)
            con.Open()
            Dim dr As SqlDataReader = cmd.ExecuteReader()
            While dr.Read()
                i += 1
                dropdownclassrecoganized.Items.Add(dr("Name").ToString())
                dropdownclassrecoganized.Items(i).Value = dr("CustomerId").ToString()
            End While
            con.Close()
        End Using
    End Using
End Sub