Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5847979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:47:43+00:00 2026-05-22T12:47:43+00:00

I am using Gridview and using Item Template text box. There are 5 text

  • 0

I am using Gridview and using Item Template text box. There are 5 text box and i am adding a new row dynamically on clicking on add row btn. in that row i have adding all text box which is empty. Now i want to validate that text box on btn click next.

now to do it?

I used required field validation its working for first time showing text box but when i am adding a new row text box its not causing the validation, I think there is some other way to give validation for dynamically added text box.

How could i validation my all dynamically added text box

Grid view which i am using..

            <Columns >

                    <asp:TemplateField>
                    <ItemTemplate>
                        <div class="otherOthersTd">
                            <asp:Label ID="lblcnt" ForeColor="#136A96" Text='<%#Eval("Count") %>' runat="server" ></asp:Label>
                            <asp:Label ID="lblId" runat="server" text='<%#Eval("Id") %>' Visible="false"></asp:Label>
                        </div>
                    </ItemTemplate>
                    </asp:TemplateField>
                   <asp:TemplateField HeaderText="First Name">

                            <ItemTemplate>

                                <asp:TextBox ID="txtName" runat="server" Text='<%# Eval("Name") %>' Width="88px"></asp:TextBox>

                            </ItemTemplate>


                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Middle Name">

                            <ItemTemplate>

                                <asp:TextBox ID="txtMName" runat="server" Text='<%# Eval("MName") %>' 
                                     Width="88px"></asp:TextBox>

                            </ItemTemplate>

                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Last Name">

                            <ItemTemplate>

                                <asp:TextBox ID="txtLName" runat="server" Text='<%# Eval("LName") %>' 
                                     Width="88px"></asp:TextBox>
                            </ItemTemplate>

                    </asp:TemplateField>

                    <asp:TemplateField HeaderText="Degree">

                            <ItemTemplate>

                                <asp:TextBox ID="txtDegree" runat="Server" Text='<%# Eval("Degree") %>' 
                                    Width="50px"></asp:TextBox> 

                            </ItemTemplate>


                    </asp:TemplateField>

                    <asp:TemplateField HeaderText="Title">

                            <ItemTemplate>
                                <asp:TextBox ID="txtTitle" runat="Server" Text='<%# Eval("Title") %>' Width="88px"></asp:TextBox>

                            </ItemTemplate>


                    </asp:TemplateField>

                <asp:TemplateField HeaderText="Email">
                     <ItemTemplate> 
                            <asp:TextBox ID="txtEmail" runat="Server" 
                                Text='<%# Eval("Email") %>' Width="88px" CausesValidation="True" ValidationGroup="a"></asp:TextBox>
                        <asp:RegularExpressionValidator ID="RegExpr" runat="server" ErrorMessage="Invalid email id" ControlToValidate="txtEmail" ValidationGroup="a" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
                         <asp:Label ID="revexp" runat="server"  > </asp:Label>
                            </ItemTemplate>

                </asp:TemplateField>

                <asp:TemplateField HeaderText="Institution">

                        <ItemTemplate>
                            <asp:TextBox ID="txtInstitution" runat="server" Text='<%#Eval("Institution") %>'></asp:TextBox>

                        </ItemTemplate>

                </asp:TemplateField>


     <asp:Button ID="btnNext" runat="server" ValidationGroup="a" CausesValidation="true" Text="Next" class="next btn" onclick="btnNext_Click"/>        

                    <asp:TemplateField>  <ItemTemplate>
                     <asp:Label ID="lblAuthor" runat="server" Text="Authorerror" Visible="false"  ForeColor="Red" Font-Bold="True" Font-Size="X-Large">*</asp:Label>
        </ItemTemplate>
                    </asp:TemplateField>


            </Columns>

            <FooterStyle BackColor="#CCCC99" />
            <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="false" ForeColor="White" />
            <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
            <HeaderStyle  Font-Bold="false" ForeColor="#136A96" />

    </asp:GridView>

my code…

protected void GridView1_OnRowCommand1(object sender, GridViewCommandEventArgs e)
        {

        if (e.CommandName.Equals(""))
        {
            lstAuthors = (List<OtherAuthors>)Session["lstAuthors"];
            if (lstAuthors.Count == 0)
            {
                OtherAuthors obj0 = new OtherAuthors();
                obj0.Count = "Author 1:";                    
                lstAuthors.Add(obj0);
            }
            int index=GridView1.Rows.Count-1;
            for (int i = 0; i < GridView1.Rows.Count; i++)
            {
                TextBox Name = GridView1.Rows[i].FindControl("txtName") as TextBox;
                TextBox MName = GridView1.Rows[i].FindControl("txtMName") as TextBox;
                TextBox LName = GridView1.Rows[i].FindControl("txtLName") as TextBox;
                TextBox Degree = GridView1.Rows[i].FindControl("txtDegree") as TextBox;
                TextBox Title = GridView1.Rows[i].FindControl("txtTitle") as TextBox;
                TextBox Email = GridView1.Rows[i].FindControl("txtEmail") as TextBox;
                TextBox Institution = GridView1.Rows[i].FindControl("txtInstitution") as TextBox;

                if(Name!=null)
                {

                lstAuthors[i].Name = Name.Text;
                lstAuthors[i].MName = MName.Text;
                lstAuthors[i].LName = LName.Text;
                lstAuthors[i].Degree = Degree.Text;
                lstAuthors[i].Title = Title.Text;
                lstAuthors[i].Email = Email.Text;
                lstAuthors[i].Institution = Institution.Text;
                }
            }
            OtherAuthors obj1 = new OtherAuthors();
            obj1.Count = "Author "+(lstAuthors.Count+1).ToString()+":";
           obj1.Name="";
           lstAuthors.Add(obj1);

           GridView1.DataSource = lstAuthors;
           GridView1.DataBind();
           for (int i = 0; i < GridView1.Rows.Count; i++)
           {
               if (GridView1.Rows.Count - 1 == i)
                   GridView1.Rows[i].Cells[8].Visible = true;
               else
                   GridView1.Rows[i].Cells[8].Visible = false;
           }
           Session["lstAuthors"] = lstAuthors;
        }
        MultipleModalitySelect1.hideChosebutton = true;

    }

private bool IsValied()
{
bool error = false;

            TextBox Name = GridView1.Rows[0].FindControl("txtName") as TextBox;
            TextBox MName = GridView1.Rows[0].FindControl("txtMName") as TextBox;
            TextBox LName = GridView1.Rows[0].FindControl("txtLName") as TextBox;
            TextBox Degree = GridView1.Rows[0].FindControl("txtDegree") as TextBox;
            TextBox Title = GridView1.Rows[0].FindControl("txtTitle") as TextBox;
            TextBox Email = GridView1.Rows[0].FindControl("txtEmail") as TextBox;
            TextBox Institution = GridView1.Rows[0].FindControl("txtInstitution") as TextBox;
            Label lblAuthor = GridView1.Rows[0].FindControl("lblAuthor") as Label;

            if (Name.Text.Length == 0 || LName.Text.Length == 0 || Degree.Text.Length == 0 ||Title.Text.Length == 0 || Email.Text.Length == 0 || Institution.Text.Length == 0)
            {
                lblAuthor.Visible = true;
                error = true;

            }
            else
            {
                lblAuthor.Visible = false;
            }

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T12:47:43+00:00Added an answer on May 22, 2026 at 12:47 pm

    You have used the validation group’s ValidationGroup="a" on your Next button, but you have not used that on the Required Field Validator. But you have used it in the Email validator.

    You have to be consistent with the Validation control and whether to put validation on all controls and button controls for it to work.

    <asp:Button ID="btnNext" runat="server" ValidationGroup="a" CausesValidation="true" Text="Next" class="next btn" onclick="btnNext_Click"/>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.