|
Hi All,
I have a text box which should be disabled, but when I tried to set the value of the text box using jQuery as below, the value is not getting posted in the code behind. I tried by making the Text box read only also, still the value is not getting posted, actually I want to make it disable only but still tried with read only to see if it can be posted.
Please anybody please help me in resolving the issue, any help like a code snippet, link or even a suggestion would help me a lot.
Below is the code and Text box I have used
$("[id$='txtBirthDate']").val(moment(updatedBirthDate).format("MM/DD/YYYY"));
<asp:TextBox ID="txtBirthDate" runat="server" ReadOnly="true" /> Or
<asp:TextBox ID="txtBirthDate" runat="server" Enabled="false" />
Thanks & Regards,
Abdul Aleem Mohammad
St Louis MO - USA
|
|
|
|
|
Disabled controls will not be included in the data posted back to the server. This is standard behaviour for all browsers, and has been since HTML forms were first introduced. There is no way to change this, short of removing the disabled attribute just before the form is submitted.
Read-only controls will be included in the data posted back to the server. However, looking at the code[^], if the ReadOnly property is set, the posted value will be ignored.
If you can work with the control being read-only rather than disabled, then you can set the readonly property from Javascript instead:
<asp:TextBox ID="txtBirthDate" runat="server" />
$(function(){
$("[id$='txtBirthDate']").prop("readonly", true);
});
Otherwise, you'll need to clear the disabled property before the form is submitted:
$(document).on("submit", "form", function(){
$("[id$='txtBirthDate']").prop("disabled", false);
});
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Awesome yes but in this mean time I fixed it by putting a hidden field there, but your solutions look good to me. Thank you.
Thanks & Regards,
Abdul Aleem Mohammad
St Louis MO - USA
|
|
|
|
|
$('[id*="_txt_Focus_Field"]').val();
your missing the *
|
|
|
|
|
I am trying to create cross domain web api, however I am still unable to call data from web api url, in my ajax function. I am currently experiencing the following syntax error, under the networks, response tag.
SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
The ’/ api/stw’ is currently being reported as 405 error, however when I call - http://apitesting.domain.com/api/stw, I am able to see the data is JSON format. So, I am little unsure, why is it failing in the ajax function.
$(document).ready(function () {
$.support.cors = true;
$.ajax({
type: "GET",
crossDomain: true,
contentType: "application/json; charset=utf-8",
// url: "/api/stw",
url: "<a href="http://apitesting.domain.com/api/stw">http://apitesting.domain.com/api/stw</a>,",
data: "{}",
dataType: "json",
success: function (data) {
console.log(data);
// var myData = JSON.parse(data)
for (var i = 0; i < data.length; i++) {
$("#tbDetails").append("<tr><td>" + data[i].Name + "</td><td>" + data[i].loan + "</td><td>" + data[i].evnt + "</td></tr>");
}
},
error: function (result) {
alert("Error");
}
});
});
I am currently hosting my cross domain web api on the above url. I have added the custom headers in the web.config file of my web api. I have also added ‘enabled.cors’ property in my stwAPIController. I tried parsing the data in ajax through the following method ‘JSON.parse(data)’,but I am still getting the same error, as mentioned above.
[EnableCors(origins: "http://apitesting.domain.com/api/stw", headers: "*", methods: "*")]
public class STWController : ApiController
{
private cdwEntities db = new cdwEntities();
<pre>
public IEnumerable<Loan> getData()
{
var data = db.Database_CRE_LoanEvents.Where(c => c.Date.Contains("2015") && c.Loan_property != null)
.Select(x => new Loan() { Name = x.Deal, loan = x.Loan_property, evnt = x.Event })
.ToList().Take(3);
return data;
}
}</pre>
Any further help, would be very much appreciated.
|
|
|
|
|
Your JSON parser says, that the token wasn't expected. This happens either when you're trying to parse array to object or object to array. Please make sure types match.
Also what do you mean by cross domain? Do you stumble upon CORS?
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
- Well as far as I know, Javascript and jQuery doesn't allow you to do cross domain calls, to protect the website from false calls to web services within your web site. But on the flip side of the coin, I know you cal call card processing services from jquery, so I need to update my knowledge on that.
- You need to check your script for errors on something like http://www.javascriptlint.com/online_lint.php[^]
- With Javascript and JQuery, you really need to use the single quote char, and not the double quote char. by using the single quote char to wrap text values, you can use the double quote char without having to escape it
e.g.
var html = '<div style="classname"></div>';
I can't tell why it's not working, but you should code it correctly first before moving forward, you could just be getting the error after the first error.
$(document).ready(function () {
2 $.support.cors = true;
3 $.ajax({
4 type: "GET",
5 crossDomain: true,
6 contentType: "application/json; charset=utf-8",
7
8 url: "<a href="http:
============================^
SyntaxError: missing } after property list
9 data: "{}",
10 dataType: "json",
11 success: function (data) {
12 console.log(data);
13
14 for (var i = 0; i < data.length; i++) {
15 $("#tbDetails").append("<tr><td>" + data[i].Name + "</td><td>" + data[i].loan + "</td><td>" + data[i].evnt + "</td></tr>");
16 }
17 },
18 error: function (result) {
19 alert("Error");
20 }
21 });
22 });
|
|
|
|
|
I want to start with asp.net mvc and I am absolutely lost with terms and concepts.
I work through a lot of microsoft trainings. But all samples mix up endless different concepts and terms.
Can somebody give me a link to some kind of "bottom-up-tutorial"?
modified 1-Apr-15 7:20am.
|
|
|
|
|
|
Hopefully, you will like this article[^] of mine about ASP.NET MVC framework.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
|
To your comment for that answer "Not Clear sir,I'm new to MVC.", please read that article I have attached.
The answer to that (sorry for going off-topic related to this thread), is that you need to send the information about your View and some other controls which were interacted through user. Which is a very common task in WPF, or Win Forms. If you view event handlers in those frameworks you find out this code,
void button_Click(object sender, EventArgs e) {
var button = sender as Button;
var name = button.Name;
}
In which, sender is the object which triggered this event. So, if you cast it to a Button object and so on.
In ASP.NET you do not get such functionality by default, which is why you have to create such functionality yourself. Which, in my opinion would be best to use native forms. Which get submitted (using action attribute) to their own pages for processing. So you can redirect the user to where you want him to be. This way, you will check for values that are related to the controller action; SignUp or SignIn . Do not complicate things, use the simplest method that can be used. It was also pointed out, that you're having variables for your HTTP GET handler, not HTTP POST. Use a model to establish similarity, or... You can use JavaScript to control how things are handled on the client (handling click on SignIn or SignUp).
Also what he tried to tell you was same, that you were having the member profileList inside your GET handler, but not inside the POST handler, where as once the form was to be submitted, it was using the POST handler action, so there was a mismatch between the ViewBags and thus caused this problem. That is why he suggested that you use a Model.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
I rarely found such a good training site in my life
Thank you very much
|
|
|
|
|
you are welcome.
நெஞ்சு பொறுக்கு திலையே-இந்த
நிலைகெட்ட மனிதரை நினைந்துவிட்டால்
|
|
|
|
|
Yes, here is an article[^] that I wrote for beginners like you. You can read it, it will guide you throughout the basics of ASP.NET MVC framework.
I hope you will find it helpful.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
|
Thanks a lot for these very helpfull information. Much better than what I found so far
I have another one
The views I found in many examples contain more or less a lot of html-code. Is is possible to use a kind of "graphical html-designer" to create this native code automatically?
|
|
|
|
|
I just learned MVC as well, oh it was painful. Totally different than web forms.
I started with one of the generic projects in VS 2013 Community Version, in which a tutorial existed for it.
This is one of them
Learn MVC (Model View Controller) step by step in 7 days – Day 1[^]
So I download the VS2013 Community Version
Fired it up, updated the program first.
Created a new Project, ASP.Net MVC 4 Web Application, and selected Razor for the HTML in the View
Then used package manager and updated all the packages to MVC5 and so forth.
From There, it creates a Responsive Design Website with login and register for accounts
So I decided to make a new website for myself and learn at the same time.
There is a preview, but basically, you write HTML off the top of you head, and just used a browser to test it.
The designers are stupid anyways and produce poor results anyways.
|
|
|
|
|
Hi,
How can I change the date format of textbox , textmode=date?
By default its yyyy/mm/dd and I want to change it to mm/dd/yyyy
asp.net visual studio 2013 framework 4.5
|
|
|
|
|
Do you have any Datepicker on Textbox ?
நெஞ்சு பொறுக்கு திலையே-இந்த
நிலைகெட்ட மனிதரை நினைந்துவிட்டால்
|
|
|
|
|
No its simple textbox with date as a text mode. but the problem is I can find any option to change the format.
|
|
|
|
|
Then ,How the user Select the Date? by typing?
நெஞ்சு பொறுக்கு திலையே-இந்த
நிலைகெட்ட மனிதரை நினைந்துவிட்டால்
|
|
|
|
|
Ops sorry I misunderstood your last message. Yes its date picker. but the format is yyyy/mm/dd.
|
|
|
|
|
Is that Ajax Calender or Jquery Calender?
நெஞ்சு பொறுக்கு திலையே-இந்த
நிலைகெட்ட மனிதரை நினைந்துவிட்டால்
|
|
|
|
|
Setting TextMode="Date" will render an HTML5 date input[^] control. This has limited browser support[^], and doesn't provide any way to override the date format.
There are two date formats in play:
- The wire format, which is how the date is sent to the client, and how it sent back to the server.
This is required to be yyyy-MM-dd in all cases; - The display format, which is how the date is presented to the user.
This is not part of the specification, so browsers are free to do what they want.
Chrome and the latest version of Opera currently use the user's local date settings.
Browsers which don't support the date input will fall back to a text input, which means they have to use the wire format.
You'll probably want to use a polyfill to get the control working in all browsers. For example:
https://github.com/chemerisuk/better-dateinput-polyfill[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|