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 8494521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:19:17+00:00 2026-06-10T23:19:17+00:00

How to put Validation in dynamicaly html table with asp.net C#? ? I want

  • 0

How to put Validation in dynamicaly html table with asp.net C#? ? I want RequireField and some other validator with this code. .
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
HtmlTable dtbl = new HtmlTable();
dtbl.Border = 5;

        dtbl.BorderColor = "black";
        dtbl.CellPadding = 6;
        dtbl.CellSpacing = 1;
        HtmlTableRow row1;
        for (int i = 0; i <= 2; i++)
        {
            row1 = new HtmlTableRow();
            row1.BgColor = "Orange";

            if (i == 0)
            {
                HtmlTableCell cell;
                for (int j = 1; j <= 4; j++)
                {
                    cell = new HtmlTableCell();
                    cell.Align = "center";
                    switch (j)
                    {
                        case 1:
                            Label l1 = new Label();
                            l1.Text = "Name";
                            l1.ForeColor = Color.White;
                            cell.Controls.Add(l1);
                            break;

                        case 2:
                            Label l2 = new Label();
                            l2.Text = "Age";
                            l2.ForeColor = Color.White;
                            cell.Controls.Add(l2);
                            break;

                        case 3:
                            Label l3 = new Label();
                            l3.Text = "Gender";
                            l3.ForeColor = Color.White;
                            cell.Controls.Add(l3);
                            break;

                        case 4:
                            Label l4 = new Label();
                            l4.Text = "EmailId";
                            l4.ForeColor = Color.White;
                            cell.Controls.Add(l4);
                            break;
                    }
                    row1.Controls.Add(cell);
                }

            }
            if (i == 1)
            {
                HtmlTableCell cell;
                for (int j = 1; j <= 4; j++)
                {
                    cell = new HtmlTableCell();
                    cell.Align = "center";
                    switch (j)
                    {
                        case 1:
                            TextBox t1 = new TextBox();
                            t1.ID = "txtName";
                            t1.ForeColor = Color.Green;
                            cell.Controls.Add(t1);
                            break;

                        case 2:
                            TextBox t2 = new TextBox();
                            t2.ID = "txtAge";
                            t2.ForeColor = Color.Green;
                            cell.Controls.Add(t2);
                            break;

                        case 3:
                            RadioButtonList rbl1 = new RadioButtonList();
                            rbl1.ID = "rbl";
                            rbl1.RepeatDirection = RepeatDirection.Horizontal;
                            rbl1.Items.Add(new ListItem("Male","Male"));
                            rbl1.Items.Add(new ListItem("Female", "Female"));
                            cell.Controls.Add(rbl1);


                            break;

                        case 4:
                            TextBox t4 = new TextBox();
                            t4.ID = "txtEmail";
                            t4.ForeColor = Color.Green;
                            cell.Controls.Add(t4);
                            break;
                    }
                    row1.Controls.Add(cell);
                }
            }
            if (i == 2)
            {
                HtmlTableCell cell = new HtmlTableCell();
                cell.ColSpan = 4;
                Button b1 = new Button();
                cell.Align = "center";
                b1.Style.Add(HtmlTextWriterStyle.BackgroundColor,"Green");
                b1.Style.Add(HtmlTextWriterStyle.Color, "White");
                b1.Style.Add(HtmlTextWriterStyle.BorderStyle, "solid");
                b1.Style.Add(HtmlTextWriterStyle.BorderColor, "White");
                b1.Style.Add(HtmlTextWriterStyle.Height, "25px");
                b1.Style.Add(HtmlTextWriterStyle.Width, "100px");
                b1.ID = "btnSubmit";
                b1.Text = "Submit";
                b1.Click+=new System.EventHandler()
                cell.Controls.Add(b1);
                row1.Controls.Add(cell);
            }
            dtbl.Controls.Add(row1);

        }

        form1.Controls.Add(dtbl);
        Page.Controls.Add(form1);

    }
}

}

  • 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-06-10T23:19:19+00:00Added an answer on June 10, 2026 at 11:19 pm

    Create a RequiredFieldValidator control, set the ControlToValidate property to the ID of the control you wish to validate, and add the new Validator control to the table cell.

    RequiredFieldValidator req = new RequiredFieldValidator();
    req.ControlToValidate = txtEmail.ID;
    // set additional properties here
    cell.Controls.Add(req);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is bothering me for some time now. I put all my validation in
I am trying to figure out where to put validation in my N-Tier Asp.net
I have this String String criteria=ESS.(BVA4+BVA5)+(-(DIESE.(BVM5+BVM6))); I want to put validations on it. It
I want to put validator so that if the user does not put the
Put value as a field makes sense only if this one represents some object's
I've been fiddling with some ASP.NET MVC3 solution structures and I have settled on
I've seen lots of book and article examples saying to put validation code in
I want to put a validation that the user always enters a value in
I have this code: @this.Html.DropDownListFor(vm => vm.FishId, new SelectList(this.Model.Fishies, FishId, FishName, this.Model.FishId), Please Select
I'm creating a user require form in my site. For this I put some

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.