Link to home
Start Free TrialLog in
Avatar of Isaac Johnson
Isaac JohnsonFlag for United States of America

asked on

How to reference asp tag that is in a variable?

Can you reference a asp tag that is passed in variable.  I have a table  that contains rows which
contain asp id's example aspTagName = txtFirstName,  fielRequired = false

I want to look at the column fieldRequired and based on value of false
remove the attribute required from the asp page using the value of
the aspTagName(txtFirstName)

Please advise.

Thanks in advance
Avatar of leakim971
leakim971
Flag of Guadeloupe image

in your Chrome web browser, open that page, do a right click on your table and click "inspect"
now on the right, do a right click on that table tag and choose "copy Outer HTML" and post it here
Avatar of Isaac Johnson

ASKER

<input name="myText" type="text" id="myText" required="required">

Open in new window


The code is a sample.
I will receive the value of the id from a table which I will store in a variable.
I want to use the variable to match the id(find control)  so I can remove required attribute.
Complete code to date trying to find answer before expansion using sql etc..
I have tried many variations, but can't find the answer.
Need help for project started last Thursday.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
//using System.Windows.Forms;

namespace WebApplication2
{
    public partial class index : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            string straspID = "myText";

            bool fieldRequired = false;

            if (fieldRequired == false)
            {

                //FindControl("myText");
                FindControl(straspID);
                myText.Attributes.Remove("required");  // I want to use variable here straspID

            }


        }

    }
}
[/code
[code]
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="index.aspx.cs" Inherits="WebApplication2.index" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="myText" runat="server" required="required"></asp:TextBox>
    
    </div>
    </form>

</body>
  
</html>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Isaac Johnson
Isaac Johnson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for your assistance.