Hi all,
I am trying to use Ajax and Jquery on master page. In my existing project i have used the Ajaxpro2.dll it's working fine. but when i am trying to use jquery then its not working.
Then in jquery script instead of $
i have used 'jquery' keyword then jquery scripts are working fine but its effects are not working.
Means when i write jQuery(mnu).show();
then its working and it shows the menus also but without effect. and when i am writing $(mnu).show('slow');
then it doesn't hide the menu and throws error "Object doesn't support this property or method."
<script language="javascript" type="text/javascript">
$(document).ready
(
function()
{
jQuery(mnu).hide();
jQuery(mnu1).hide();
jQuery(mnu2).hide();
jQuery(mnu3).hide();
jQuery(mnu4).hide();
jQuery(SubMnu).hide();
jQuery(SubMnu1).hide();
}
)
$(document).click
(
function()
{
jQuery(mnu).hide();
jQuery(mnu1).hide()
jQuery(mnu2).hide()
jQuery(mnu3).hide();
jQuery(mnu4).hide();
jQuery(SubMnu).hide();
jQuery(SubMnu1).hide();
}
)
function showMnu()
{
jQuery(mnu).show();
jQuery(mnu1).show();
jQuery(mnu2).show();
jQuery(mnu3).show();
jQuery(mnu4).show();
}
function show(id)
{
if(id == mnu)
{
jQuery(SubMnu).show();
}
else
{
jQuery(SubMnu1).show();
}
}
</script>
In below mentioned code i have called server side ajaxmethod MasterPage.pl_chkmail
, MasterPage.HomeLink_Click
, MasterPage.changepasword_Click
, MasterPage.Logout_Click
on client side.
<script language="javascript" type="text/javascript">
setTimeout("chk_Mail()", 4000)
var a;
var chk = null;
function chk_Mail()
{
var userid= <%=Session("UserLogged") %>
var chat=0;
chat=<%=Session("Chatadmin") %>
if(<%=Session("PartnerId")%> == 10)
{
var ds=MasterPage.pl_chkmail(userid,chat)
var sqlds=ds.value;
if (sqlds==true)
{
if(chk==null || chk.closed)
{
chk=window.open('Chat.aspx','_blank','width=500,height=420,left=310 ,top=220,resizable=no')
}
}
a = setTimeout("chk_Mail()", 8000);
}
}
function redirect_default()
{
var userid= "<%=Session("UserLogged") %>"
var usertypeid="<%=Session("UserTypeId") %>"
var chk = MasterPage.HomeLink_Click(userid)
if (chk.value == 1)
{
if (usertypeid == 7)
{
window.location="Visaprocess_mst.aspx"
}
else
{
window.location="default.aspx"
}
}
}
function redirect_changepassword()
{
var userid= "<%=Session("UserLogged") %>"
var chk = MasterPage.changepasword_Click(userid)
if (chk.value == 1)
{
window.location="ChangePassword.aspx"
}
}
function redirect_logout()
{
var userid= "<%=Session("UserLogged") %>"
var chk = MasterPage.Logout_Click(userid)
if (chk.value == 1)
{
window.location="loginform.aspx"
}
}
</script>
Below code is my code behind of masterpage.
Option Explicit On
'
Imports System.Data
Imports System.Data.SqlClient
Partial Class MasterPage
Inherits System.Web.UI.MasterPage
#Region "My Variable Declarations"
Dim sqlCmd As SqlCommand
Dim sqlDs As DataSet
Dim acc As DataAccessLayer
Dim rghts As ChkRights
'
Dim vl_UsrId As Integer
Public SqlCon As New SqlConnection(ConfigurationManager.AppSettings("connectionString"))
#End Region
#Region "Events - Mixed General "
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
AjaxPro.Utility.RegisterTypeForAjax(GetType(MasterPage))
Response.Cache.SetNoStore()
Response.Cache.SetCacheability(HttpCacheability.NoCache)
If Session("PartnerId") <> 10 Then
chat.Visible = False
menu.Visible = False
Else
chat.Visible = True
If Session("UserTypeId") = 1 Or Session("UserTypeId") = 2 Then
menu.Visible = True
End If
End If
If CStr(Session("UserName")) = "" Then
Session.Abandon()
Response.Redirect("Partneroptions.aspx")
Exit Sub
End If
End Sub
#End Region
#Region "My ClientSide Procedures & Functions"
<AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.Read)> _
Public Function pl_chkmail(ByVal user As Integer, ByVal chatadmin As Integer) As Boolean
Dim bStatus As Boolean = False
'
Try
Dim chatid As Integer
sqlDs = New DataSet
sqlCmd = New SqlCommand
'
Dim sqladp As New SqlDataAdapter(sqlCmd)
sqlCmd.Connection = SqlCon
'
If (SqlCon.State = ConnectionState.Closed Or SqlCon.State = ConnectionState.Broken) Then
SqlCon.Open()
End If
'
If chatadmin <> 1 Then
With sqlCmd
.CommandText = "usp_chkmail"
.CommandType = CommandType.StoredProcedure
.Parameters.Add("@user", SqlDbType.Int).Value = user
.Parameters.Add("@chatid", SqlDbType.Int).Direction = ParameterDirection.Output
End With
Else
With sqlCmd
.CommandText = "usp_chkadminmail"
.CommandType = CommandType.StoredProcedure
.Parameters.Add("@user", SqlDbType.Int).Value = user
.Parameters.Add("@chatid", SqlDbType.Int).Direction = ParameterDirection.Output
End With
End If
'
sqladp.Fill(sqlDs)
chatid = sqlCmd.Parameters("@chatid").Value
SqlCon.Close()
sqladp = Nothing
'
If chatid <> 0 Then
bStatus = True
Else
bStatus = False
End If
Catch ex As Exception
Finally
sqlDs = Nothing
sqlCmd = Nothing
End Try
Return bStatus
End Function
<AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.Read)> _
Public Function HomeLink_Click(ByVal UserId As String) As Integer
rghts = New ChkRights
rghts.pg_check_AssignStatus(UserId, 0, 0)
rghts.pg_check_AssignStatusforchkavail(UserId)
rghts.pg_check_AssignStatusforcancel(UserId)
rghts.pg_check_AssignStatusforenquiry(UserId)
rghts.pg_check_AssignStatusforpayment(UserId)
Return 1
End Function
<AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.Read)> _
Public Function changepasword_Click(ByVal UserId As String) As Integer
rghts = New ChkRights
rghts.pg_check_AssignStatus(UserId, 0, 0)
rghts.pg_check_AssignStatusforchkavail(UserId)
rghts.pg_check_AssignStatusforcancel(UserId)
rghts.pg_check_AssignStatusforenquiry(UserId)
rghts.pg_check_AssignStatusforpayment(UserId)
rghts = Nothing
Return 1
End Function
<AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.Read)> _
Public Function Logout_Click(ByVal UserId As String) As Integer
rghts = New ChkRights
rghts.pg_UpdateIsloggedField("", UserId)
rghts.pg_check_AssignStatus(UserId, 0, 0)
rghts.pg_check_AssignStatusforchkavail(UserId)
rghts.pg_check_AssignStatusforcancel(UserId)
rghts.pg_check_AssignStatusforenquiry(UserId)
rghts.pg_check_AssignStatusforpayment(UserId)
rghts = Nothing
Return 1
End Function
#End Region
End Class
Many thanks!
Ankur