After setting local server, I want to send data to SQL server from HTML page. I'm using C#, ASP.NET. But the problem is, while I'm using post method, it just showing me blank result without sending string input properly to my mssql server.

Below is part of my Write.aspx file, which mainly takes info from users through HTML text input. And I used post method to deal with info in Write_Check.aspx (actually in behind code, Write_Check.aspx.cs)

<%@ Page Language = "C#" AutoEventWireup = "true" 
CodeFile = "Write.aspx.cs" Inherits = "Article_Write" %>

<!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>
    <title>Title</title>
    <script language = "javascript">
    </script>
</head>
<body>
    <form id = "form1" method = "post" action = "Write_Check.aspx">
        <center>
            <table width = "100%" border = "0" cellpadding = "2" cellspacing = "3">
                <tbody><tr align = "left">
                    <td colspan = "3">
                        <h2>Write Article</h2>
                    </td>
                </tr>
                <tr align = "left">
                    <td width = "100px">
                        Writer
                    </td>
                    <td width = "600px">
                        <input type = "text" id = "writername" name = writer_name />
                    </td>
                </tr>

and my Write_Check.aspx is just one line.

<%@ Page Language = "C#" AutoEventWireup = "true" CodeFile = "Write_Check.aspx.cs" Inherits = "Save_Check" %>

and this is my Write_Check.aspx.cs. CWebBase is just a collection of methods for db connection so that I can use it easily for other cs files as well.

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Save_Check : CWebBase
{

    protected void Page_Load(object sender, EventArgs e)
    {
        string name, password, title, content;
        //find form name
        name = Request.Form["writer_name"];
        password = Request.Form["password_check"];
        title = Request.Form["title_check"];
        content = Request.Form["content_check"];

        CDatabase _db = new CDatabase();

        string sql = "INSERT INTO dbo.article (writerName, passwords, title, content) values('"
            + name + "','" + password + "','" + title + "','" + content + "')";

        _db.ExecuteSQL(sql);
        _db.Dispose();

        Response.Redirect("List.aspx");

    }
}

I'm not sure why the post method I used here work properly.

Related posts

Recent Viewed