0

Default3.aspx

This is my first page. in which i have two textbox and one submit button, onclick of submit button calling Default4.aspx page, where i have written the data insertion code.

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js">
    </script>

    <script type="text/javascript">
$(function() {
$("#add").click(function() {

var login = $("#loginid").val();
var pass = $("#pass").val();
var dataString = 'login='+ login +'&pass='+pass;

$("#flash").show();
$("#flash").fadeIn(400).html('<img src="ajax-loader.gif" align="absmiddle"> <span class="loading">Loading Comment...</span>');

$.ajax({
type: "POST",
url: "Default4.aspx",
data: dataString,
cache: false,
success: function(html){
$("#display").after(html);
//document.getElementById('content').value='';
//document.getElementById('content').focus();
$("#flash").hide();
}
});
 return false;
});
});
    </script>

</head>
<body>
    <form name="frm_add" id="frm_add">
    <input type="text" name="loginid" id="loginid" />
    <input type="text" name="pass" id="pass" />
    <input type="submit" id="add" value="Submit" />
    <div id="flash"></div>
<div id="display"></div>
    </form>
</body>
</html>

Default4.aspx

<%@ Import Namespace="System.Data.SqlClient" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <%
    Dim login, pass As String
        login = Request.QueryString("login")
        pass = Request.QueryString("pass")
        Dim cs As String = ConfigurationManager.ConnectionStrings("eExamSolutionConnection").ConnectionString
        Dim cn As New SqlConnection(cs)
        Dim cmd As New SqlCommand
        ' MsgBox(dob)
        cmd.CommandText = "INSERT INTO ADMIN_CREDENTIAL VALUES ('" & login & "','" & pass & "')"
        cmd.Connection = cn
        cmd.Connection.Open()
        cmd.ExecuteNonQuery()
        cmd.Connection.Close()
        cmd.Dispose()
        cn.Dispose()
        Response.Write("Added")
     %>
</body>
</html>

But, blank row inserted into my table, whenever i'm submitting the value. Need help !!

2 Answers 2

3

Use Fiddler and check if everything is alright.

Change the TYPE of JQuery Ajax to GET and see if it works or not.

$.ajax({
type: "GET",
url: "Default4.aspx",
data: dataString,
cache: false,
success: function(html){
$("#display").after(html);
//document.getElementById('content').value='';
//document.getElementById('content').focus();
$("#flash").hide();
Sign up to request clarification or add additional context in comments.

3 Comments

thanks !! it works, i have another question, is that possible to put the Default4.aspx code into Default3.aspx code-behind, so that i can save one page for the same process ..??
@coders : It's better if you separate this two because you are sending data to second page using AJAX
By the way, @TheJonasPersson's answer is also correct and should work.
1

Try changing your posted data

data: {login: $("#loginid").val(), pass: $("#pass").val()},

Then, on your Default4.aspx, grab the data from the form data, not the querystring. Request.Form("login") and Request.Form("pass").

Comments

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.