Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
ASP.NET
<%@ Page Title="" Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script src="http://code.jquery.com/jquery-latest.js"></script>
    <script>
        $(document).ready(function () {
            alert("Testing")
            $("#SponsorID").focusout(function () {
                var sponsor = $('#SponsorID').val();
                var sponsorname = $('#Text1').val();
                //alert(sponsor);
                $.ajax({
                    type: "POST",
                    url: "HTMLControl.aspx/GetSponsorName",
                    data: "{'username':'" + sponsor + "'}",
                    contentType: "application/json; charset=utf-8",
                    Method: "POST",
                    dataType: "json",
                    success: function (response) {
                        var names = response.d;
                        //alert(names);
                        $('#Text1').val(names);
                    },
                    failure: function (response) {
                        alert("Not Valid");
                    }
                });
            });
        });
  </script>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
     <div>
        SponsorID :   
        <input id="SponsorID" type="text" required="required"  runat="server"/>    
        <input id="Text1" type="text"/>    
        <br /><br />
        Email :   
        <input id="Email" type="email" required="required"  runat="server"/>
        <br /><br />
        Mobile Number :    
        <input type="text" id="MobileNumber" name="Mobile" pattern="[789][0-9]{9}"  maxlength="10" minlength='10' required="required"  runat="server"/>
        <br /><br />
        <asp:Button ID="Save" runat="server" Text="Save" />
    </div>


Imports System.Web.Services
Imports System.Web.Script.Serialization
Imports System.Data
Imports System.Data.SqlClient
Partial Class _Default
    Inherits System.Web.UI.Page
    <webmethod> _
    Public Shared Function GetSponsorName(ByVal username As String) As String
        Dim msg As String = username
        Dim cn As New SqlConnection
        Dim comm As New SqlCommand
        Dim sqltrans As SqlTransaction
        Dim connectStr As String


        If cn.State = ConnectionState.Closed Then
            connectStr = ConfigurationManager.ConnectionStrings("connectstr").ToString()
            cn.ConnectionString = connectStr
        End If

        Dim Da As New SqlDataAdapter
        Dim Ds As New DataSet

        comm.CommandText = "select Membername from Registration where MemberiD = '" & username & "'"
        comm.CommandTimeout = 0

        comm.Connection = cn
        comm.Transaction = Nothing
        Da.SelectCommand = comm
        Da.Fill(Ds)

        comm.Connection = cn

        If Ds.Tables(0).Rows.Count > 0 Then
            msg = Ds.Tables(0).Rows(0)(0).ToString()
        Else
            msg = "Sponsor ID Not Valid"
        End If


        Return msg
    End Function
End Class</webmethod>
Posted
Updated 22-Jun-15 22:15pm
v2
Comments
Andy Lanng 23-Jun-15 4:19am    
Please be more discernible when you post a question.

The posts allow for tag elements to be used to change the format of the content. Please make sure that you either paste "as code block" (should come up as an option when you paste, or that you carefully edit the code and wrap it with 'pre' tags. If you don't then the code is hard to read and some may be lost between parsed tags.

Also, try not to code dump. You should include some detail and background in your question.

I have edited this for you so you will hopefully get more views
Sreekanth Mothukuru 23-Jun-15 4:23am    
Have you enabled Page methods on the master page in order to access the webmethod server side?
F-ES Sitecore 23-Jun-15 4:26am    
First off is your code being called? Do you have anything with an ID of "SponsorID" on the page (view the page source from the browser)? When you use master pages .net changes your control IDs. So you need code like

$("#<%=SponsorID.ClientID%>")

If the code is being called use Fiddler or the browser's dev tools to examine the network traffic as that will let you know the underlying error. It could be that the url you are targeting isn't valid.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900