Hi all,
I'm getting "PageMethods is undefined" while clicking on the OK button which is in the "ajaxToolkit:ModalPopupExtender".How to overcome this issue? Below is my code.
aspx page:
<script>
function onOk() {
//$get('Paragraph1').className = styleToSelect;
PageMethods.callservermethod()
}
</script>
<form id="ajaxForm" runat="server">
<asp:ScriptManager ID="manager" runat="server" EnablePageMethods="True">
</asp:ScriptManager>
<%-- EnablePartialRendering="true" EnableScriptGlobalization="true" EnableScriptLocalization="true"--%>
<div>
<asp:Label ID="fnamelbl" Text="First Name" runat="server"></asp:Label>
<asp:TextBox ID="fnamectl" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="fnameval" ControlToValidate="fnamectl" ErrorMessage="<b>Required Field<br />Please Enter</b>" Display="dynamic" runat="server"></asp:RequiredFieldValidator>
<ajaxToolkit:ValidatorCalloutExtender ID="ajaxfnameval" TargetControlID="fnameval" runat="server" HighlightCssClass="validatorCalloutHighlight"></ajaxToolkit:ValidatorCalloutExtender>
<asp:Label ID="lnamelbl" Text="Last Name" runat="server"></asp:Label>
<asp:TextBox ID="lnamectl" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="lnameval" ControlToValidate="lnamectl" ErrorMessage="<b>Required Field<br />Please Enter</b>" Display="dynamic" runat="server"></asp:RequiredFieldValidator>
<ajaxToolkit:ValidatorCalloutExtender ID="ajaxlnameval" TargetControlID="lnameval" runat="server" HighlightCssClass="validatorCalloutHighlight"></ajaxToolkit:ValidatorCalloutExtender>
<asp:Button ID="savebtnctl" Text="Save" runat="server" />
</div>
<%-- <p id="Paragraph1"><%= GetContentFillerText() %></p><br />
<p id="Paragraph1"></p><br />--%>
<asp:Panel ID="Panel1" runat="server" Style="display: none" CssClass="modalPopup">
<asp:Panel ID="Panel3" runat="server" Style="cursor:move;background-color:#DDDDDD;border:solid 1px Gray;color:Black">
<div>
<p>The below details are stored in DB</p>
</div>
</asp:Panel>
<div>
<p><%=fnamectl.Text%><br /><%= lnamectl.Text %></p>
<p style="text-align: center;">
<asp:Button ID="OkButton" runat="server" Text="OK" />
<asp:Button ID="CancelButton" runat="server" Text="Cancel" />
</p>
</div>
</asp:Panel>
<ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender" runat="server"
TargetControlID="savebtnctl"
PopupControlID="Panel1"
BackgroundCssClass="modalBackground"
OkControlID="OkButton"
OnOkScript="onOk()"
CancelControlID="CancelButton"
DropShadow="true"
PopupDragHandleControlID="Panel3" />
</form>
aspx.vb page:
Partial Class _Default
Inherits System.Web.UI.Page
Dim ajxwork As New action
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
'Protected Sub savebtnctl_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles savebtnctl.Click
' SetCtlToOjects()
' Dim flag As Integer = ajxwork.Save()
' If flag = 1 Then
' MsgBox("Your data has been saved.")
' Else
' MsgBox("Sorry!!! Your data failed to be saved.")
' End If
'End Sub
<WebMethod()> _
Public Sub callservermethod()
SetCtlToOjects()
Dim flag As Integer = ajxwork.Save()
If flag = 1 Then
MsgBox("Your data has been saved.")
Else
MsgBox("Sorry!!! Your data failed to be saved.")
End If
End Sub
Public Sub SetCtlToOjects()
ajxwork.firstname = fnamectl.Text
ajxwork.lastname = lnamectl.Text
End Sub
End Class
class.vb
Public Class action
Private _firstname As String
Private _lastname As String
Public Property firstname() As String
Get
Return _firstname
End Get
Set(ByVal value As String)
_firstname = value
End Set
End Property
Public Property lastname() As String
Get
Return _lastname
End Get
Set(ByVal value As String)
_lastname = value
End Set
End Property
'<System.Web.Services.WebMethod()> _
Public Function Save() As Integer
Dim SqlConn As New SqlConnection(ajaxconnection.ajxconnect)
Dim SqlCmd As New SqlCommand
SqlConn.Open()
SqlCmd.Connection = SqlConn
SqlCmd.CommandType = CommandType.StoredProcedure
SqlCmd.CommandText = "asp_patsave"
'SqlCmd.Parameters.Add(New SqlParameter("@dotnet.itags.org.firstname", SqlDbType.NVarChar))
'SqlCmd.Parameters.Add(New SqlParameter("@dotnet.itags.org.lastname", SqlDbType.NVarChar))
SqlCmd.Parameters.AddWithValue("@dotnet.itags.org.firstname", _firstname)
SqlCmd.Parameters.AddWithValue("@dotnet.itags.org.lastname", _lastname)
SqlCmd.ExecuteNonQuery()
SqlCmd.Dispose()
SqlConn.Dispose()
Return 1
End Function
End Class
Thanks in Advance :)
Hi,
Please note that a pageMethod has to be static(c#) / shared(vb) .
Change the line Public Sub callservermethod() to Public Shared Sub callservermethod() and try again.
Hope this helps.
No comments:
Post a Comment