userName = Global.getComponent('centerRegion').UserName.getValue();
该代码弹出错误
{"browserEvent":"'Global.getComponent(...).UserName' is null or not an object","button":-1,"ctrlKey":false,"xy":[0,0]}
当我在此表单上运行时:
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
所有内容都显示并从屏幕上的表单中正确保存,所以值就在那里,但我认为我的Javascript是错误的。
编辑:
生成的HTML:
xtype:'fieldset'
,title:'Connection Parameters'
,id:'params',autoHeight:true
,titleCollapse:true
,border:true
,collapsible:false
,labelWidth:139
,anchor:'100%'
,items:[
{xtype:'textfield',validationEvent:'blur',enableKeyEvents:true,anchor:'100%',value:'IDWSSample',fieldLabel:'User Name',itemId:'UserName',name:'UserName',allowDecimals:false,decimalPrecision:0,validator:function(value){var isCustomValid = true;if (this.ux_isInitialized == true) {isCustomValid = function(value){if (value.match(/<[a-zA-Z!\/]{1}/)) return 'If using the "<" character, it must not be followed by "!" or "/" or any letter.';if (value.match(/.*&#.*/)) return 'If using the "&" character, it must not be followed by "#".';return true;}(value);if (typeof(isCustomValid) == 'string') return isCustomValid;}if (isCustomValid == null) isCustomValid = true;return isCustomValid;}}
,
{xtype:'textfield',validationEvent:'blur',enableKeyEvents:true,anchor:'100%',value:'TcYg7m*a',fieldLabel:'Password',itemId:'Password',name:'Password',allowDecimals:false,decimalPrecision:0,inputType:'password'
}
,
{xtype:'textfield',validationEvent:'blur',enableKeyEvents:true,anchor:'100%',value:'http://sample.idws.syndication.kbb.com/VehicleInformationService2008R2.svc?wsdl',fieldLabel:'URL',itemId:'LoginUrl',name:'LoginUrl',allowDecimals:false,decimalPrecision:0,validator:function(value){var isCustomValid = true;if (this.ux_isInitialized == true) {isCustomValid = function(value){if (value.match(/<[a-zA-Z!\/]{1}/)) return 'If using the "<" character, it must not be followed by "!" or "/" or any letter.';if (value.match(/.*&#.*/)) return 'If using the "&" character, it must not be followed by "#".';return true;}(value);if (typeof(isCustomValid) == 'string') return isCustomValid;}if (isCustomValid == null) isCustomValid = true;return isCustomValid;}}
,
{xtype:'combo_transform',validationEvent:'blur',enableKeyEvents:true,anchor:'100%',fieldLabel:'Market Value',id:'ddlMarketValues',itemId:'ddlMarketValues',name:'ddlMarketValues',allowDecimals:false,decimalPrecision:0,id:'EXT_ddlMarketValues'
,el:null
,typeAhead:true
,triggerAction:'all'
,transform:'ddlMarketValues'
,forceSelection:true
,selectOnFocus:true
,lazyRender:true
,resizable:true
,editable:false
答案 0 :(得分:1)
查看生成的源代码并检查ASP.NET为centerRegion生成的名称。根据您的ASP.NET版本,可能会在名称中添加自动生成的后缀。
如果是这种情况,请更新名称以匹配正在生成的名称,并查看是否修复了该名称。
答案 1 :(得分:0)
不确定Global.getComponents方法的来源,但我的猜测是你有错字或者你没有正确访问字段值。尝试使用常规javascript查找字段,或者使用jQuery更轻松。
尝试:
var userName = document.getElementById('UserName').value;
或使用jQuery:
var userName = $("#UserName").val();
...假设'centerRegion'和'UserName'是您网页上元素的ID值。
如果您没有使用jQuery,那么您可以尝试asp.net方式:
var userName = $find('UserName','centerRegion').value;