2012-10-17 45 views
2

我想通過一個會話變量jquery。基本上我想要的是當我點擊我的'btnVenSUSend'按鈕時,我想要一個警告框彈出並讓用戶知道他們的信息已被提交。當它通過代碼將信息寫入數據庫時​​,我正在填充會話變量。即使表單沒有完成,我也會彈出警告框出現問題。如果我的會話變量=發送,我只需要提醒。通過vb.net會話變量jquery

這裏是我的JQuery:

<script type="text/javascript"> 
    $(document).ready(function ($) { 
     $("#btnVenSUSend").click(function ($) { 
      var mySend = '<%=Session("mySend") %>' 
      if (mySend == "send") { 
       alert("Your request has been submitted, you will be notified when the process is complete."); 
      } 
     }); 
    }); 

</script> 

這背後是我的代碼。如果VenType的條件正確,它會通過並設置變量。這是有效的,因爲我可以遍歷代碼並查看結果。

If VenType = "E" Then 
     str = "send" 
     Session("mySend") = str 

     Dim con As New SqlConnection(ConfigurationManager.ConnectionStrings("VendorPortalConnectionString").ToString()) 
     Dim cmdO As New SqlCommand("Select UserID, Password FROM VendorMaster where UserID = '" & loggedIn & "'", con) 
     con.Open() 

     Dim myReader As SqlDataReader 
     myReader = cmdO.ExecuteReader() 

     Dim UserID As String = "" 
     Dim psw As String = "" 

     If myReader.HasRows Then 
      Do While myReader.Read 
       UserID = myReader.GetString(0) 
       psw = myReader.GetString(1) 
      Loop 
     Else 
     End If 
     con.Close() 
     myReader.Close() 

這只是我的jQuery不工作。我的jquery不在外部js中。它位於我的.aspx頁面的頭部。

+2

在你的代碼背後你在設置會話變量?沒有看到它被執行的地方,我不得不假設你總是將會話(「mySend」)設置爲「發送」,因此,JavaScript警報將始終執行。 –

+0

你是否證實「var mySend」實際上被打印了?如果這是在外部js文件中,它將不會呈現.net標記 – Eonasdan

回答

0

我可以看到你在你的jQuery代碼中的mySend var聲明中缺少一個分號。當你添加它時它工作嗎(見下文)?

var mySend = '<%=Session("mySend") %>';