I have something like this.
<input type="text">
I want enable/disable it based in certain variable value in server side.
I have tried this.
<input type="text" <%= DisableServiceInfo ? "disabled":"" %>/>
but not working.
I know this can be done.
<input type="text" disabled="<%= DisableServiceInfo ? "disabled":"invalid value" %>"/>
but this is not a valid mark-up. Because the only valid way to enable control is to remove disabled attribute.
I am not asking how value can be supplied based on variable but how attribute in injected
Please don't answer the ways to set it server side or by javascript. I just want to know if it is possible in this way?
Is this webforms? If you want to do this by the book, you can manually add an Id, and Runat="Server". Once you've done that, your control can be manipulated in your code-behind.
If your Id is ServiceInfo, you could do:
ServiceInfo.Attributes["disabled"] = "disabled";
Related
I am writing a test that can login to a site. I am using C#, with Selenium.
1)there are two ID for password?! why would someone code it like this?
2)the ID contain number which is dynamic and keep changing each time the page is loaded.
the only different is with the name ID is:
id="txtPassword_155799780_I_CLND"
id="txtPassword_155799780_I"
I tried everything.
driver.FindElement(By.XPath(".//div[starts-with(#id,'txtPass') and contains(#text(),'I_CLND')]"));
driver.FindElement(By.XPath("//input[starts-with(#id,'txtPassword_')]")[2]);
<input class="dxeEditArea_DevEx dxeEditAreaSys dxh0" id="txtPassword_156029875_I_CLND" type="text" tabindex="0" saveddisplay="[object Object]">
<input class="dxeEditArea_DevEx dxeEditAreaSys dxh0" id="txtPassword_156029875_I" name="txtPassword_156029875" onfocus="ASPx.EGotFocus('txtPassword_156029875')" onblur="ASPx.ELostFocus('txtPassword_156029875')" onchange="ASPx.EValueChanged('txtPassword_156029875')" type="password" saveddisplay="[object Object]" savedspellcheck="[object Object]" spellcheck="false" style="display: none;">
Thanks
Your question is kind of all over the place. I would try and use something like the below xpath. I can't tell if you have two "password" elements displaying on the page or just one. Post the html and we can help you better.
//input[contains(#id, 'txtPassword')][1]
or
//input[contains(#id, 'txtPassword') and #type='text']
I have two html input in one form, and I am setting them to required as follows:
<input id="email" name="textfield36" type="text" class="input3" runat="server" required="required" />
<input id="frEmail" name="textfield36" type="text" class="input3" runat="server" required="required" />
I need to set the Required attribute to false to one of the two inputs from c#. For example:
if (language == "English")
{
frEmail.Attributes.Add("required", "false");
}
else
{
email.Attributes.Add("required", "false");
}
This is causing an issue, because if the language is English, then the user only needs to fill the specified fields and the way it's happening now is that he's obliged to fill them all and vice versa. Note that on load I'm hiding the fields not relating to the language.
Can anyone help on this?
The required attribute is a Boolean attribute. That means the value is ignored. It's presence on the element all that matters. You need to remove the required attribute, not change its value.
email.Attributes.Remove("required");
In my form I need to insert different inputs of type "hidden".
The inputs must be html controls with "name" and "id's". Because I send this form to a external url.
For the validation I do runat=server in a hidden input and then I can use requiredfieldvalidator.
But the problem is when I look in the source after visiting the page the name is changed. for example
<input type="hidden" name="hotelIdform" value="" runat="server" id="hotelIdform">
changed to
<input name="ctl00$ctl00$Master_Body$child_center_content$hotelIdform" type="hidden" id="hotelIdform" value="b4ba78fc-0b62-4809-9dca-000972573139" />
and i used ClientIDMode="Static" , just ID is okay
please help me
It seems you are using Master pages and not using static client ID. Thus, ASP.NET is changing the ID while it compiling the page.
You need to set ClientIDMode to Static.
Please refer this SO post
I can get value from html input by:
Request["inputID"]
But, How to get data-myatt attribute from input below in server-side:
<input id="input1" type="text" value="value" data-myatt="my date" />
If you're using ASP.net web forms then all you have to do is to add the attribute runat="server" to the input tag, then you will have access to it and it's attributes.
If you changed the attribute on the client side and you want to have access to it on the server side, you'll have to put that data in another hidden input and get your value from there...
You can get input value by the following method,
var input_value = document.getElementById('input1').value;
To get the specific attribute value you need,
var attribute_value = document.getElementById('input1').getAttribute('data-myatt');
or if you are using Jquery you can simply get attribute value by using,
$('#input1').attr('data-myatt);
Why not create a hidden html input for your request to pass back to your code behind:
<input type="text" name="costCenterInput" data-isComboBox="true" />
<input type="hidden" name="costCenters" />
in your c#:
String costCenterInput = Request["costCenterInput"];
String costCenters = Request["costCenters"];
Or you can do some postback nastiness, see my answer here:
How to use __doPostBack()
I have a page where many postback clicks are there.
In this page many input elements there, which values are i am geting from server side using Request[]. like below
.aspx
<input id="txtRefTypeCtrlType_3" name="txtRefTypeCtrlType_3" lastvalue="4" CTRLtype="4" style="display: none;">
.cs
string strCTRLtype = Request["txtRefTypeCtrlType_3"];
now i have a scenario, where i need to get the CTRLtype attribute value.
Can we get the attribute value using Request[] or something else.
Please advise.
Thanks.
No, you can't get the attribute value on the server side because it isn't posted. The only real way of achieving this is to create a hidden field with the attribute value and use that:
<input type="hidden" name="ctrlType_3" value="4" />
Codebehind:
string attrValue = Request["ctrlType_3"];