Get variables in c# from ajax call

Posted by fzshah76 on Stack Overflow See other posts from Stack Overflow or by fzshah76
Published on 2010-06-16T19:21:38Z Indexed on 2010/06/16 20:32 UTC
Read the original article Hit count: 574

Filed under:
|
|
|

I've got an Ajax call for log in here is the code:

//if MOUSE class is clicked
$('.mouse').click(function () {
    //get the form to submit and return a message
    //how to call the function 

    var name = $('#name').val();
    var pwd2 = $('#pwd2').val();
    $.ajax({
    type:"POST",               
     url: "http://localhost:51870/code/Login.aspx",
     data: "{ 'name':'" + $('#name').val() + "', 'pwd':'" + $('#pwd2').val() + "' }",
     contentType: "application/json; charset=utf-8",
     dataType: "json",
     context: document.body, 
     success: function () {
        //$(this).addClass("done");
        $(this).hide();
         $('.mouse, .window').hide();
                         }
});

});

the problem is I can't seem to catch name and pwd variables in Login page's preinit event or page load event here is the code in c#:

 protected void Page_PreInit(object sender, EventArgs e)
{
    //taking javascript argument in preinit event
    //from here I'll have to build the page for specific lookbook
    var name = Request.QueryString["name"];
    var pwd = Request.QueryString["pwd"];

}

protected void Page_Load(object sender, EventArgs e)
{
    var name = Request.QueryString["name"];
    var pwd = Request.QueryString["pwd"];
    SignIn(name);
}

I can't seem to get username name and password in c# side, help is appreciated.

Here is my final javascript code c# code remains the same:

<script type="text/javascript">

        $(document).ready(function () {    
 //if MOUSE class is clicked
            $('.mouse').click(function () {

                var name = $('#name').val();
                var pwd = $('#pwd').val();
                $.ajax({
               url: "http://localhost:51870/code/Login.aspx?name="+ name +"&pwd="+pwd,
               context: document.body, 
               success: function () {
                    //$(this).addClass("done");
                    $(this).hide();
                     $('.mouse, .window').hide();
                                     }
            });

            });

     });
</script>

Thanks Zachary

© Stack Overflow or respective owner

Related posts about c#

Related posts about jQuery