I have this code and I want it to transforms it to asp.net controls in label and literal ?
How?
` <input type="text" id="_Email" class="contact-form" name="Email" placeholder="Email address">`
That particular element would actually be a TextBox MSDN TextBox
It would look like this <asp:TextBox runat="server" ID="Email" CssClass="contact-form" />. this would then render <input type="text" id="_Email" class="contact-form" />
The Literal control doesn't produce an HTML element and allows you to add text/html to your page and not wrap it in any other HTML.
The Label control actually outputs a <span></span> and puts your Text in between it.
Related
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 have a asp.net page which contains checkbox controls like below:
<input name="REQUEST_DA_TYPE$0" disabled="disabled" id="REQUEST_DA_TYPE_0" type="checkbox" checked="checked"/>
<label for="REQUEST_DA_TYPE_0">
Text - Accept
<input name="REQUEST_DA_TYPE$1" disabled="disabled" id="REQUEST_DA_TYPE_1" type="checkbox" checked="checked"/>
<label for="REQUEST_DA_TYPE_1">
Text - Refuse
Now I need to dynamically change both label's text in C# page.
Help me to solve this.
Why don't you use server controls instead of native html elements directly? That's one of the main features of ASP.NET, isn't it? So, instead of doing this...
<input name="REQUEST_DA_TYPE$0" disabled="disabled" id="REQUEST_DA_TYPE_0" type="checkbox" checked="checked"/>
<label for="REQUEST_DA_TYPE_0">
<input name="REQUEST_DA_TYPE$1" disabled="disabled" id="REQUEST_DA_TYPE_1" type="checkbox" checked="checked"/>
<label for="REQUEST_DA_TYPE_1">
Why don't you do this...?
<asp:CheckBox ID="REQUEST_DA_TYPE_0" runat="server" Checked="True" Enabled="false" Text="Text - Accept"/>
<asp:CheckBox ID="REQUEST_DA_TYPE_1" runat="server" Checked="True" Enabled="false" Text="Text - Refuse"/>
Then, from code behind you can change whatever you want. For example, the text...
REQUEST_DA_TYPE_0.Text = "I've been changed";
enable it...
REQUEST_DA_TYPE_0.Enabled = false;
the font color...
REQUEST_DA_TYPE_0.ForeColor = System.Drawing.Color.Blue;
etc, etc.
My .aspx looks like the following:
<div id="valueIntroduction" type="text" class="labelarea" runat="server">
<input name="$labeluniversityid" type="text" id="labeluniversityid" style="color:#7D110C;border:0;background-color:#C0D5F2;width:100%" />
</div>
.cs File looks like:
if (results.Read())
{
labeluniversityid.value = results["TEXT_CONTENT"].ToString();
}
Exactly what am trying do is am getting the data from the database and displaying it in the valueIntroduction div. That is workiing fine. Now i added a text box with readonly mode. So that in my page if I press EDIT button, the value could be edited.
Use a TexBox component:
<asp:TextBox ID="labeluniversityid" runat="server" CssClass="yourcssclass"></asp:TextBox>
As for the styling:
.yourcssclass
{
color:#7D110C;
border:0;
background-color:#C0D5F2;
width:100%
}
Then, in your code behind you can easily use it like this:
labeluniversityid.Text = results["TEXT_CONTENT"].ToString();
Keep in mind that ASP.NET Controls are translated into common HTML tags, so you can wrap it and style it as you would with any other normal input of type text.
Also: type="text" is not valid for div
Try putting runat="server" attribute in <input id="labeluniversityid"> tag.
Or use a <asp:TextBox> control as areks suggests.
You need to add -
runat="server"
to your input field
Or, even better, use an
<asp:textBox ..>
I have following input tags inside table in asp.net
<td class="style18">
<asp:CheckBox ID="chkContentTone" onclick="enableGroupBoxTone()"
runat="server" Text="Content Tone" CssClass="ChkBoxStyle"/>
</td>
<td class="styleCntTon">
<input type="radio" id="rdBtnPositive" name="q2" title="Posotivetitle" value="positive"/>
<label for="rdbtnPositive" class="RadioGroup">Positive</label>
<input type="radio" id="rdBtnNegative" name="q2" title="Negativetitle" value="negative"/>
<label for="rdBtnNegative" class="RadioGroup">Negative</label>
<input type="radio" id="rdBtnNeutral" name="q2" title="Neutraltitle" value="neutral"/>
<label for="rdBtnNeutral" class="RadioGroup">Neutral</label>
</td>
but when I put an if condition in, the radio button's the show an error.
Any ideas why this is occurring?
Try to use Asp.net controls:
<asp:RadioButton runat="server" ... />
The markup you posted does not include server side controls hence those controls cannot be accessed via server side code.
Looking at what you want seems like you would need an asp:RadioButton
once you add a asp:radiobutton you can access these controls in your server side code.
Change this:
<input type="radio" id="rdBtnPositive" name="q2" title="Posotivetitle" value="positive"/><label for="rdbtnPositive" class="RadioGroup">Positive</label>
To this:
<asp:RadioButton id="rdBtnPositive" Label="Positive" runat="server" />
Then you can do:
if(rdBtnPositive.Checked)
{
//code it...
}
You'll need to do that for all three radiobutton's, each should have a unique id and be a server side control, namely asp:RadioButton.
you should use asp:RadioButton to be able to access in code behind.
So basically replace all "input" tags with "asp:RadioButton" and remove non sensible properties like Type.
asp:RadioButton usage example
I am using asp.net C#
I am also using the jQuery UI Calendar control.
calendar control
It appears the calendar control wants to work with an input control with an ID of "datepicker".
<input type="text" id="datepicker" />
I want to use value of the input control in my code behind but seeing how it is not an asp.net control I am not sure how I can reference it in the code behind.
Does anyone know how to get the value of the input control in the code behind?
use
<input type="text" id="datepicker" name="datepicker" />
and in the code behind:
Request.Form["datepicker"]
In fact, Form property of Request is populated with form values.
Here you have to mention your form name which contains input tag
<input name="txtemail" id="txtemail" runat="server" type="text" class="cssspa" form="form"/>
in C#
string email = txtemail.Value.ToString();
now u can get data from textbox
If you want to use basic form pulling, you need to add a name attribute:
<input type="text" id="datepicker" name="datepicker" />
if(Page.IsPostBack)
{
string value = Request.Form["datepicker"];
}
Alternatively, you can mark is as an HtmlInputControl
<input type="text" id="datepicker" runat="server" />
System.Web.UI.HtmlControls.HtmlInputControl datepickerControl = this.FindControl("datepicker") as System.Web.UI.HtmlControls.HtmlInputControl;
if(datepickerControl != null)
string value = datepickerControl.Value;
You can access the value via the Request object like onof wrote, or you can turn every html tag into a server control by adding the attribute runat:
<input type="text" id="datepicker" runat="server" ClientIdMode="static" />
The attribute ClientIdMode="static" ensures that the tags ID is not changed by the ASP.NET runtime.
Then you can access the input by the autogenerated member datePicker.
Since you explicitly say code-behind, I assume you probably want to stay with the WebForms/Controls model? With clientidmode you can do that while also having a determinite id value for the calendar.
<asp:TextBox id="datepicker" ClientIDMode="Static" runat="server" />
Then you can interact directly with the control from the code-behind as normal.
But, the calendar control does not require a specific ID. You can initialize it with whatever ID you want
<asp:TextBox id="DateTextBox" runat="server" />
<script>
$(function() {
$( "#<%=DateTextBox.ClientID%>" ).datepicker();
});
</script>