2012-04-12 14 views
0

我有一個表格,當我輸入它是這樣的:asp.net菜鳥的jQuery + RUNAT =「服務器」與所有的選項聲明的形式

<form name="formLogin" id="formLogin" action="index.aspx" method="post"> 

我的JavaScript的作品,和源代碼該網頁與上面列出的相同。

當我鍵入它是這樣的:

<form name="formLogin" id="formLogin" runat="server"> 

我的頁面崩潰。我基本上與第三方模板並嘗試將其轉換爲asp.net。

所顯示的源代碼是這樣的:

<form id="formLogin" action="index.aspx" method="post"> 

看來,當我使用runat="server"選項它重新創建表單元素沒有名字?如果在.net上,並且想要處理Jquery和Server端驗證,我必須使用runtat="server"嗎?

如果我不包含runat="Server",我仍然可以在頁面後面的代碼中進行驗證嗎?

 $(document).ready(function() {  
      onfocus(); 
      $(".on_off_checkbox").iphoneStyle(); 
      $('.tip a ').tipsy({gravity: 'sw'}); 
      $('#login').show().animate({ opacity: 1 }, 2000); 
      $('.logo').show().animate({ opacity: 1,top: '30%'}, 800,function(){   
       $('.logo').show().delay(1200).animate({ opacity: 1,top: '0%' }, 300,function(){ 
        $('.formLogin').animate({ opacity: 1,left: '0' }, 300); 
        $('.userbox').animate({ opacity: 0 }, 200).hide(); 
       });   
      }) 
     }); 

     $('.userload').click(function(e){ 
      $('.formLogin').animate({ opacity: 1,left: '0' }, 300);    
       $('.userbox').animate({ opacity: 0 }, 200,function(){ 
        $('.userbox').hide();    
       }); 
     }); 

    $('#but_login').click(function(e){    
      if(document.formLogin.username.value == "" || document.formLogin.password.value == "") // BREAKS HERE 
      { 
       showError("Please Input Username/Password"); 
       $('.inner').jrumble({ x: 4,y: 0,rotation: 0 }); 
       $('.inner').trigger('startRumble'); 
       setTimeout('$(".inner").trigger("stopRumble")',500); 
       setTimeout('hideTop()',5000); 
       return false; 
      }  
     hideTop(); 
     loading('Checking',1);  
     setTimeout("unloading()", 2000); 
     setTimeout("Login()", 2500); 
    }); 

function Login(){ 
    $("#login").animate({ opacity: 1,top: '49%' }, 200,function(){ 
     $('.userbox').show().animate({ opacity: 1 }, 500); 
      $("#login").animate({ opacity: 0,top: '60%' }, 500,function(){ 
       $(this).fadeOut(200,function(){ 
        $(".text_success").slideDown(); 
        $("#successLogin").animate({opacity: 1,height: "200px"},500);     
       });       
      }) 
    }) 
    setTimeout("window.location.href='dashboard.html'", 3000); 
} 

$('#alertMessage').click(function(){ 
    hideTop(); 
}); 

function showError(str){ 
    $('#alertMessage').addClass('error').html(str).stop(true,true).show().animate({ opacity: 1,right: '0'}, 500); 

} 

function showSuccess(str){ 
    $('#alertMessage').removeClass('error').html(str).stop(true,true).show().animate({ opacity: 1,right: '0'}, 500);  
} 

function onfocus(){ 
       if($(window).width()>480) {     
         $('.tip input').tipsy({ trigger: 'focus', gravity: 'w' ,live: true}); 
       }else{ 
         $('.tip input').tipsy("hide"); 
       } 
} 

function hideTop(){ 
    $('#alertMessage').animate({ opacity: 0,right: '-20'}, 500,function(){ $(this).hide(); }); 
} 

function loading(name,overlay) { 
     $('body').append('<div id="overlay"></div><div id="preloader">'+name+'..</div>'); 
       if(overlay==1){ 
       $('#overlay').css('opacity',0.1).fadeIn(function(){ $('#preloader').fadeIn(); }); 
       return false; 
     } 
     $('#preloader').fadeIn(); 
} 

function unloading() { 
     $('#preloader').fadeOut('fast',function(){ $('#overlay').fadeOut(); }); 
} 
+0

你能後,當您切換到使用'RUNAT ='server''對停止運行jQuery代碼的例子嗎? – TLS 2012-04-12 19:26:48

+0

你在頁面上有多種表單嗎? ASP.NET並不是全部:http://msdn.microsoft.com/en-us/magazine/cc163736.aspx#S4 – 2012-04-12 19:26:56

+0

此登錄頁面全部在一個表格下。 @TimSchmelter – 2012-04-12 19:29:12

回答

1

如果你不runat=Server您將無法訪問實際的形式/任何控制沒有標示碼RUNAT =服務器後面的(服務器端)。請發佈你的jQuery代碼,如果我看到奇怪的東西,我可以編輯這個答案。

使用$("#username").val().length與您的密碼相同,以查看是否存在名稱/密碼。你有js和jquery混合使得找到罪魁禍首更加困難。

if($("#username").val().length == 0 && $("#password").val().length == 0)

//enter here if one is missing 
+0

任何想法,當我添加runat =「server」時,爲什麼這會打破一切?我刪除它,我的jQuery驗證,我添加它,它假裝表單不存在。 – 2012-04-12 19:26:10

+0

@JamesWilson你需要發佈所有的細節。你的jQuery做什麼?我沒有看到任何理由爲什麼這會崩潰。 – JonH 2012-04-12 19:27:44

+1

可能與您的jQuery選擇器和應用runat =「server」標記時生成的控件的ID有關。你沒有足夠的代碼讓我們告訴。 – 2012-04-12 19:28:11

相關問題