ASP.NET Empty Label Text - c#

I am using set value with jquery but i couldn't get value from label
jquery code is here
$(document).ready(function() {
$("input:radio[name=paketler]").click(function () {
var value = $(this).val();
$('#<%=lblradio.ClientID%>').html(value);
});
})
i used hiddenfield,.val(),.text() but i am seeing text value on label but i couldn't get value in codebehind. can you help me ? how can i get value in codebehind.

try :
$('#' +'<%=lblradio.ClientID %>').val(value);
or
$('#<%=lblradio.ClientID %>').val(value);

Related

onmouseover change text based on value from database

My code is in C#. I have a span with id change. I need to change the text onmouseover to a value from the database. I got the value and assign it to a label and I made it hidden. Now on mouseover I want to get the value of the hidden label.
Here is my script.
<script>
$(document).ready(function () {
$("#change").mouseover(function () {
$('#change').text("value of label");
});
$("#change").mouseout(function () {
$('#change').text("Investor");
});
});
</script>
How can I do it?
Solved By Me :)
I have solved the issue. It was because I had visible=false in the label properties and I should replace it with style="display:none;" .
.Regarding my Script. It is as below .
$(document).ready(function () {
var originalText = $('#change').text();
$('#change').mouseover(function () {
var hiddenVar = $('[id$="NewAccountsLabel"]').html();
$('#change').text(hiddenVar);
});
$('#change').mouseleave(function () {
$('#change').text(originalText);
});
});
Why don't you use the label value , your label should have the id
$(document).ready(function () {
Var lblvalue = $('#label').val();
$("#change").mouseover(function () {
$('#change').text(lblvalue);
});
$("#change").mouseout(function () {
$('#change').text("Investor");
});
The jQuery events are mouseover and mouseleave events. More on this here
// save the previous value in javascript variable
var originalText = $('#change').text();
//mouse event on mouseover the span
$('#change').mouseover(function() {
// read the value from the hidden label
var hiddenVar = $('#NewAccountsLabel').text();
// assign the new value from the hidden var
$('#change').text(hiddenVar);
});
//mouse event when mouse leaves the span
$('#change').mouseleave(function() {
// assign the original value when it leaves
$('#change').text(originalText);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.1/jquery.min.js"></script>
<span id="change"> Investor</span>
<label id='NewAccountsLabel' hidden> value from DB </label>

ASP.NET Can't set value to datepicker from code behind

I have a datepicker field
$(function () {
$("#dateTextBox").datepicker({
changeMonth: true,
changeYear: true
});
$("#dateTextBox").datepicker("option", "dateFormat", "dd/mm/yy");
});
In code behind, on button click, I'm trying to set value to datepicker field:
dateTextBox.Value = date.ToString("dd/MM/yyyy");
But after postback, textbox is empty...
In order to achieve this, you need to read details from client side using hidden field. This hiddenfield value can be set at server side.
For example:
create hidden field on page
<asp:HiddenField id="hdnDate" runat="server" />
set date string in hiddenField :
protected void button_Clicked (...)
{
DateTime dt = DateTime.Now;
hdnDate.Value = dt.Year.ToString() + "," + (dt.Month - 1 ).ToString() + "," + dt.Day.ToString();
}
now, on document.ready of jquery event, do this
$(document).ready(function() {
$("#dateTextBox").datepicker({
changeMonth: true,
changeYear: true
});
dtString = $("#<%=hdnDate.ClientID%>").val();
dtString = dtString.split(',');
var defaultDate = new Date(dtString[0], dtString[1], dtString[2]);
$("#dateTextBox").datepicker("setDate",defaultDate);
});
Try this:
dateTextBox.Value = DateTime.Now.ToString("yyyy-MM-dd");

Grab Gridview textbox input value Jquery

I have built the following Gridview (Employees and their weekly target):
Desired result: I have a submit button at the bottom which will take all the data from the Gridview using jQuery and push it into my database.
At the moment, I cannot even retrieve the textbox values though, i have the following code:
$(document).ready(function () {
$("#btnSubmit").click(function () {
$("#GridView1 td").each(function () {
var value = $(this).text();
alert(value);
});
});
});
This Selects all the "Table Data" cells... It is selecting the names perfectly, but as soon as it gets to a textbox, it doesnt get the value I type in, it just alerts nothing.
I have tried the following too, each with different, but not the desired results:
.html
.val
.innerHTML
Would anyone be able to point out where I am going wrong please? please let me know if you need anymore info...
You have to check if the control exists in the table cells or not
Give this a try
var value = $(this).find('input').length > 0 ? $(this).find('input').val() : $(this).text();
Hope this will work!
You must select the input textbox in your selection as given below
$(document).ready(function () {
$("#btnSubmit").click(function () {
$("#GridView1 td input").each(function () {
var value = $(this).val();
alert(value);
});
});
});

How to get a variable value from aspx(jquery) to its codebehind?

I have a jQuery variable like
Default.aspx:
$(function () {
$("#divimgbtnGo").click(function () {
var ServiceNo = $(".ddlService option:selected").val();
});
});
Here I am getting value into ServiceNo. I want to use these value in my codebehind (Default.aspx.cs).
Can anyone please help?
All information in search is about getting codebehind to aspx. SO could not found any useful result and stuck here
Have a hidden feild in your aspx page then pass your variable value to that hidden field like this
$(function () {
$("#divimgbtnGo").click(function () {
$("#<%= yourhiddenfield.ClientID %>").val($(".ddlService option:selected").val());
});
});
In your Code behind get the value of hidden field as yourhiddenfield.Value
You can use, for example, a Hidden field, so ASP.NET will take care of transfering that data to the server and mapping it to CLR datatype after.
You can take hidden field and set ServiceNo value to hiddenField and u can use hiddenfield in server side.
add hidden field in Default.aspx page
<asp:HiddenField ID="hdnServiceNo" runat="server" />
set hidden field value.
$(function () {
$("#divimgbtnGo").click(function () {
var ServiceNo = $(".ddlService option:selected").val();
$('#hdnServiceNo').val(ServiceNo );
});
});

Textbox onchange event

So I have a text box, where I add an onchange event of markAsException.
My javascript is -
function markAsException(recordID) {
//alert("Exception");
//mark exception column
document.getElementById("ctl00_cpMain_lblScrollException_" + recordID).innerText = "Exception";
document.getElementById("ctl00_cpMain_lblScrollException_" + recordID).style.color = "#FF0000";
document.getElementById("ctl00_cpMain_tdScrollException_" + recordID).style.backgroundColor = "#99CCFF";
//enable comments ddl and remove blank (first item)
document.getElementById("ctl00_cpMain_ddlCommentId_" + recordID).disabled = false;
document.getElementById("ctl00_cpMain_ddlCommentId_" + recordID).focus();
document.getElementById("ctl00_cpMain_ddlCommentId_" + recordID).options[0] = null;
}
What I want to do is, when a user changes the value in a textbox, to mark a column as "Exception", and then focus a drop down list where they have to chose the reason for the exception.
This is what happens.. If I am on that text box and change it, then tab, it tabs to the drop down list.
However, if I change the value and then simply click in another text box on the form, I don't focus the drop down list.
How would I accomplish that?
I would suggest using JQuery's change() function.
The advantage is that it will be more stable across different browsers.
Something like:
$('#<%= TextBox1.ClientID %>').change(function(){
// extract the recordID from the textbox - perhaps with an attribute?
markAsException(recordID);
});
My comment was getting longer so I'm expanding:
Take a look at the JQuery documentation for setting this up as the page finishes loading. If tb is the ID of your textbox your selector would be
$('#<%= tb.ClientID %>')
I would suggest you replace your code and use
tb.Attributes.Add("recordID", recordId.ToString());
This will add the ID you need onto the textbox tag. Once you're in the function I outlined above you can use the following selector to get the recordID in javascript
var recordID = $('#<%= TextBox1.ClientID %>').attr('recordID');
All together
$(document.ready(function(){
$('#<%= tb.ClientID %>').change(function(){
var recordID = $('#<%= tb.ClientID %>').attr('recordID');
if(recordID){
markAsException(recordID);
}
});
});

Categories