2010-09-02 70 views
0
userName = Global.getComponent('centerRegion').UserName.getValue(); 

值該代碼會彈出錯誤的Javascript不拉從形式

{"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

不知道在哪裏的Global.getComponents方法是,但我的猜測是,你有一個錯字有或者您沒有正確訪問字段值。嘗試使用常規JavaScript查找字段,或者使用jQuery更容易。

嘗試:

var userName = document.getElementById('UserName').value; 

或使用jQuery:

var userName = $("#UserName").val(); 

...假設 'centerRegion' 和 '用戶名' 是你的頁面上的元素的ID值。

如果你不使用jQuery,那麼你可以嘗試在asp.net方式:

var userName = $find('UserName','centerRegion').value; 
+0

當我嘗試$ find時,它說$ find沒有被定義。當我嘗試第一個建議時,出現此錯誤「document.getElementById(」UserName「)爲null」 – Scott 2010-09-02 14:18:31

+1

請確保在aspx頁面中有一個ScriptManager對象,以便您可以使用$ find。 null從document.getElementById表示「UserName」不是實際的id值。這可能類似於「ctl00_UserName」。您可以通過將控件的ClientID值注入服務器端代碼的頁面腳本中來訪問它。 – Silkster 2010-09-02 14:35:03

+0

仍然沒有能夠得到這個工作。有任何想法嗎? – Scott 2010-09-02 16:26:41

1

查看生成的源代碼,並檢查由ASP.NET生成的centerRegion名稱。根據您的ASP.NET版本,可能會自動生成後綴添加到名稱。

如果是這樣,請更新名稱以匹配正在生成的名稱,並查看是否修復了該名稱。