Javascript没有从表单中提取值
该代码会弹出错误Javascript没有从表单中提取值,javascript,asp.net,Javascript,Asp.net,该代码会弹出错误 userName = Global.getComponent('centerRegion').UserName.getValue(); 当我在此表单上运行它时: {"browserEvent":"'Global.getComponent(...).UserName' is null or not an object","button":-1,"ctrlKey":false,"xy":[0,0]} 屏幕上的表单会正确显示和保存所有内容,因此值就在那里,但我认为我的Javas
userName = Global.getComponent('centerRegion').UserName.getValue();
当我在此表单上运行它时:
{"browserEvent":"'Global.getComponent(...).UserName' is null or not an object","button":-1,"ctrlKey":false,"xy":[0,0]}
屏幕上的表单会正确显示和保存所有内容,因此值就在那里,但我认为我的Javascript拉取它是错误的
编辑:
生成的HTML:
Using Form As New WebControls.Forms.Form
With Form
.ID = "Test"
.ItemName = "connector"
With .Toolbar
.UseDefaultButtons = False
.AddButton(Forms.FormToolbar.ButtonType.Save)
.AddButton(Forms.FormToolbar.ButtonType.Cancel)
.AddButton("Test Connection", "testConnection", "icon-button-testconnection", , "Test")
End With
With .CenterRegion
.Id = "centerRegion"
With .AddFieldSet("Activate Service")
.Id = "activate"
.LabelWidth = 0
Dim cb As New Forms.Control("IsActive", "", "", Model.IsActive, Forms.Control.ControlType.CheckBox)
cb.BoxLabel = "Activate Service"
.AddControl(cb)
End With
With .AddFieldSet("Connection Parameters")
.Id = "params"
.LabelWidth = 150
.AddControl(New Forms.Control("UserName", "", "User Name", Model.UserName, Forms.Control.ControlType.TextField))
.AddControl(New Forms.Control("Password", "", "Password", Model.Password, Forms.Control.ControlType.Password))
.AddControl(New Forms.Control("LoginUrl", "", "URL", Model.LoginUrl))
End With
End With
Response.Write(.ToString)
End With
End Using
xtype:'fieldset'
,标题:'Connection Parameters'
,id:'params',自动高度:true
,titleCollapse:true
,border:true
,可折叠:false
,标签宽度:139
,主播:'100%'
,项目:[
{xtype:'textfield',validationEvent:'blur',enableKeyEvents:true,anchor:'100%',value:'IDWSSample',fieldLabel:'User Name',itemId:'UserName',allowDecimals:false,decimalPrecision:0,validator:function(value){var isCustomValid=true;if(this.uxisinitialized==true){isCustomValid=function(value.match){if(value.match)(/不确定Global.getComponents方法来自何处,但我猜您可能有输入错误,或者您没有正确访问字段值。请尝试使用常规javascript查找字段,或者使用jQuery更轻松地查找字段
尝试:
或者使用jQuery:
var userName = document.getElementById('UserName').value;
…假设“centerRegion”和“UserName”是页面上元素的id值
如果未使用jQuery,则可以尝试asp.net方式:
var userName = $("#UserName").val();
查看生成的源代码并检查由ASP.NET for centerRegion生成的名称。根据您的ASP.NET版本,可能会自动生成后缀添加到名称中
如果是这种情况,请更新名称以匹配正在生成的名称,并查看是否已修复该名称。当我尝试$find时,它表示未定义$find。当我尝试第一个建议时,会出现以下错误:“document.getElementById(“UserName”)为空”确保您的aspx页面中有ScriptManager对象,以便可以从文档中使用$find.null。getElementById表示“UserName”不是实际的id值。它可能类似于“ctl00\u UserName”。您可以通过在服务器端代码中将控件的ClientID值注入页面的脚本来访问它。@谢谢您的更正。@Scott-您可以发布生成的HTML吗?@Scott,不确定那是什么,但它不是HTML。看起来像是js对象的一部分?在浏览器中打开页面并查看源代码以获取发送给bro的内容wser@Scott:这是生成的JavaScript,不是HTML。
var userName = $("#UserName").val();
var userName = $find('UserName','centerRegion').value;