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"];
Related
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";
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 am using C# Asp.Net for creating a website. I have created an HTML5 date element in the web page. The date element is along with many other .Net elements (i.e textbox). I am unable to retrieve the value of date element.Below is my code
<asp:TextBox ID="TextBox10" runat="server"></asp:TextBox>
<input type="date" id="myDate" name="sel_date" value="YY-MM-DD" />
I have tried tried many methods from stackoverflow but nothing worked. i.e
1- String.Format("{0}", Request.QueryString["sel_date"]); // Not Working <br>
2- myDate.Value; <br><br>
I can get the value of textbox as its a .Net element but how can I get the value of Html5 Date element ?.
Try this code in .Aspx file
<input type="date" runat="server" id="myDate" name="sel_date" value="YY-MM-DD" />
and Access the value like this in .Aspx.cs file
String DOB = myDate.Value;
You will never get the value of HTML control directly in code behind.
Just a clarification to the above statement before it becomes "truth" :)
Yes, you can get any/all input field values, whether they are "server side control" or not (plain HTML <input />), from "code behind".
There is nothing wrong with this plain HTML5 <input /> field, it doesn't have to be a "server side" control:
<input type="date" id="myDate" name="sel_date" value="YY-MM-DD" />
It will be in the Request.Form collection on POSTback:
Request.Form["sel_date"];
Request["sel_date"];
The original code "didn't work" because it was looking for it in Request.QueryString["sel_date"]
Hth....
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 HTML hidden field:
<input type="hidden" title="aaa" value="bbb" id="TAB" runat="server" />
I want to access the title attribute from the code behind, like if its a input="text", there is a option TAB.ToolTip, but not for "hidden". Is it possible to get the title since it exists like an attribute?
I assume that your control is recognized by the webserver as a HtmlInputHidden instance. You should be able to fetch all attributes of the control using the Attributes property (see http://msdn.microsoft.com/en-us/library/system.web.ui.htmlcontrols.htmlcontrol.attributes(v=vs.90))
In you code behind:
TAB.Attributes["title"] = "aaa";