0

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.

8
  • That's Save_Check not Write_Check, is it a typo? Commented Jul 22, 2015 at 8:03
  • Oh yes it is a typo. Sorry for that. Commented Jul 22, 2015 at 8:06
  • You forgot to add the runat="server" tag for your form. Check w3 tutorial for more info. Commented Jul 22, 2015 at 8:12
  • I do not think that's the only problem. I actually tried the runat = "server" before I upload this question but didn't work Commented Jul 22, 2015 at 8:17
  • Try it simple first, <form runat="server"> without all the parameters and see what happens. Commented Jul 22, 2015 at 8:18

1 Answer 1

1

Ok, so, from what i can see you're not actually submiting the form (not in the code you've posted anyway).
In order to see the values in code behind you have to submit the form, by clicking a button (or anything else you want).
For example:

<form id="form1" runat="server">
//data to submit
<asp:Button id="button1" Text="Click me!" runat="server" OnClick="submit" />
</form>

After the form is submitted you can check the values just like you tried:
name = Request.Form["writer_name"];

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

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.