2

I would like to set a value on a webpage using windows application form and using GetElementById and SetAttribute("value", desiredValue) I have created a command list which navigates through the webpage and puts in values:

currentCommands.Enqueue(new Command("setvalue", "45", 
"setPublishMin"));

whereas "setPublishMin" links to the ID of the textbox on the wepage via a commandHandler class and csv file The ID looks like this

id="WebpageAdminTheme_ComponentList_ctl02_wtExpandableInnerBlock_wtExpandableSe ction__Sets"]

Once I have filled in the textbox and add select another textbox in which I want to pass different values the ID will be the same apart from "ctl02" changing to "ctl04" etc. in the ID. So I was wondering if there is an easier way to pass over the values than by using IDs

CatiaV5
  • 168
  • 1
  • 1
  • 10

2 Answers2

0

You can try and use ClientIdMode

<asp:ContentID="content"ContentPlaceHolderID="content"runat="server"ClientIDMode="Static" >    
    <asp:TextBox runat="server"ID="txtName"ClientIDMode="Static" />        
</asp:Content> 

Static This option forces the control’s ClientID to use its ID value directly. No naming container naming at all is applied and you end up with clean client ids:

<inputname="ctl00$content$txtName"type="text"id="txtName" />
Athanasios Kataras
  • 25,191
  • 4
  • 32
  • 61
0

If you want to set the same values for all inputs from "ctl02" to "ctl04", then you can achieve this by class also. Give the same class to all the controls and set the value using the class.

var elms = document.getElementsByClassName('class-name')
for (var i = 0; i < elms.length; i++) {
    elms[i].setAttribute("value", "foo");
}
Mittal Patel
  • 2,732
  • 14
  • 23