[英]Javascript not Alerting String Variable Value From Database in Code behind C#, but alerting integer variable, why?
I am facing issue with alerting Database value fetching in code behind C# and alerting them at client side. 我在用C#背后的代码警告数据库值获取并在客户端警告它们时遇到问题。 Issue is for string value.
问题是字符串值。 Eg - Suppose any user has set their password as integer, then the code is easily alerting the value, but if the password is string then it's not alerting any thing.
例如-假设任何用户都将其密码设置为整数,那么代码很容易警告该值,但是如果密码是字符串,则它不会警告任何事情。 Even it not alerting as 'undefined', while value is there with variable.
即使值不可变,它也不会发出“未定义”警报。
See the below example 请参阅以下示例
Code Behind C# C#背后的代码
public string strPassword = string.Empty;
public string strEmailPassword = string.Empty;
var objData = UserBusiness.GetUserByID(strUserID);
if (objData != null)
{
strPassword = objData.Password;
strEmailPassword = objData.EmailPwd;
}
At JavaScript 在JavaScript
$(document).ready(function () {
var strPwd = <%= strPassword %> ;
$('#<%= txtLoginPassword.ClientID%>').val(strPwd);
var strEmailPwd = <%= strEmailPassword %> ;
$('#<%= txtEmailPwd.ClientID%>').val(strEmailPwd);
});
Change your JavaScript code like this. 像这样更改您的JavaScript代码。
$(document).ready(function () {
var strPwd = '<%= strPassword %>' ;
$('#<%= txtLoginPassword.ClientID%>').val(strPwd);
var strEmailPwd = "<%= strEmailPassword %>" ;
$('#<%= txtEmailPwd.ClientID%>').val(strEmailPwd);
});
Reason: Strings must be place inside quotes '
or "
and integers doesn't need quotes 原因:字符串必须放在引号
'
或"
并且整数不需要引号
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.