0

I have a weird issue that is probably simple here is the code

js file

    function visitorAction(firstnm,lastnm)
{

    var xmlhttp;


    xmlhttp=new XMLHttpRequest();


   xmlhttp.onreadystatechange=function()
   {
    if(xmlhttp.readyState==4 && xmlhttp.status==200)
        {
           document.getElementById('placeholder').innerHTML=xmlhttp.responseText;

        }

   }

  xmlhttp.open("GET", "Handler1.ashx?firstname="+firstnm+"&lastname="+lastnm, true);
   xmlhttp.send();
}

My webform -yes the js file is being correctly called

 <form id="form1" runat="server">
    <div>
    <table>
            <tbody>
                <tr>
                    <td>First Name</td>
                    <td><asp:TextBox ID="firstnameTextBox" runat="server"></asp:TextBox></td>
                    <td><asp:RequiredFieldValidator 
                    ID="RequiredFieldValidator1" 
                    runat="server" 
                    ErrorMessage="Fill in your first name"
                    ControlToValidate="firstnameTextBox"></asp:RequiredFieldValidator></td>
                </tr>
                <tr>
                    <td>Last Name</td>
                    <td><asp:TextBox ID="lastnameTextBox" runat="server"></asp:TextBox></td>
                    <td><asp:RequiredFieldValidator 
                        ID="RequiredFieldValidator2" 
                        runat="server" 
                        ErrorMessage="Fill in your last name"
                        ControlToValidate="lastnameTextBox"></asp:RequiredFieldValidator></td>
                </tr>
            </tbody>
        </table>
        <asp:LinkButton ID="LinkButton1" runat="server" OnClientClick="return visitorAction('firstnameTextBox','lastnameTextBox');">Login</asp:LinkButton>
        <asp:LinkButton ID="LinkButton2" runat="server" PostBackUrl="Registration.aspx">Register</asp:LinkButton>
    </div>
    <div id = "placeholder">

    </div>

my handler

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace CSC515_Project5_GREGORY
{

    public class Handler1 : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {

            context.Response.ContentType = "text/html";
            context.Response.Write("<html>");
            context.Response.Output.WriteLine("hello");
            context.Response.Write("</html>");

        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}

my issue is that the function does not work when I fill in anything in my input fields and click "login". It should just return "hello" for testing but nothing happens and no console errors occur. When I click "login" without filling in any field it does what it is supposed to do. what gives?

1
  • small off topic use docs.jquery.com/API/1.1/AJAX for ajax call it add to your code cross browserx functionality . Commented Mar 10, 2012 at 8:13

1 Answer 1

2

remove the <html> part in the handler.context.Response.Output.WriteLine("hello"); is enough for you. see this site for more information about how to use ajax in asp.net applications.

Sign up to request clarification or add additional context in comments.

2 Comments

no dice :/ like i said in the question it works when I don't have data entered.
put return false; after the ` xmlhttp.send();`.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.