I have multiple textboxes added dynamically through jQuery. But due to some reasons, the id of some textboxes is missing.
I want to make a check on all the textboxes if they have their IDs or not. If not then add it using C#.
I have done this part from backend:
// Say I have 3 textboxes added in string "Question" here.
string Question="<input data-size="0" data-type="0" id="Answer1" placeholder="Answer1" type="text" /><br/>
<br/>
<input data-size="0" data-type="0" id="Answer2" placeholder="Answer2" type="text" /><br/>
<br/>
<input data-size="0" data-type="0" id="Answer3" placeholder="Answer3" type="text" /><br/>
<br/>
";
string textboxTagPattern= @"(<input)([^>]*)(type=\"")(text)(\"")([^>]*)(/>)";
Regex rgx = new Regex(textboxTagPattern, RegexOptions.IgnoreCase);
MatchCollection questionInputText = rgx.Matches(Question);
string textboxes ="";
if (questionInputText.Count > 0){
for (int i = 0; i < questionInputText.Count; i++)
{
textboxes = questionInputText[i].Value;
var id = textboxes.IndexOf("id");
if (textboxes.IndexOf("id") == -1)
{
I am stuck here. How to add the id attribute to the textboxes?
}
}
}