Click here to Skip to main content
15,889,808 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
XML
<%@ Page Language="C#" MasterPageFile="~/VisitorMaster.master" AutoEventWireup="true" CodeFile="city.aspx.cs" Inherits="Default4" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <table cellspacing="5" id="tbl" runat="server" width="100%">
    <tr>
        <td style="width:20%">
            <asp:Label ID="lblcityid" runat="server" Text="Id"></asp:Label>
        </td>
        <td style="width:80%">
            <asp:TextBox ID="txtcityid" runat="server"></asp:TextBox>
            <asp:RequiredFieldValidator ID="reqcityid" runat="server"
                ErrorMessage="Please Enter Id" ControlToValidate="txtcityid">*</asp:RequiredFieldValidator>
        </td>
    </tr>
    <tr>
        <td style="width:20%">
            <asp:Label ID="lblname" runat="server" Text="City Name"></asp:Label>
        </td>
        <td style="width:80%">
            <asp:TextBox ID="txtname" runat="server"></asp:TextBox>
            <asp:RequiredFieldValidator ID="reqname" runat="server"
                ErrorMessage="Please City Name" ControlToValidate="txtname">*</asp:RequiredFieldValidator>
        </td>
    </tr>
    <tr>
        <td style="width:20%">
            <asp:Label ID="lbldesc" runat="server" Text="Description"></asp:Label>
        </td>
        <td style="width:80%">
            <asp:TextBox ID="txtdesc" runat="server"></asp:TextBox>
            <asp:RequiredFieldValidator ID="reqdesc" runat="server"
                ErrorMessage="Please Enter Description" ControlToValidate="txtdesc">*</asp:RequiredFieldValidator>
        </td>
    </tr>
     <tr>
        <td style="width:20%">
            <asp:Label ID="lblstateid" runat="server" Text="State Name"></asp:Label>
        </td>
        <td style="width:80%">
            <asp:DropDownList ID="ddstateid" runat="server" AutoPostBack="True"
                DataSourceID="sqldtsrcstateid" DataTextField="vcname"
                DataValueField="nostateid">
            </asp:DropDownList>
            <asp:SqlDataSource ID="sqldtsrcstateid" runat="server"
                ConnectionString="<%$ ConnectionStrings:HTHConnStr %>"
                SelectCommand="SELECT [nostateid], [vcname] FROM [state]"></asp:SqlDataSource>
        </td>
    </tr>
    <tr>
        <td style="width:20%">
            <asp:Label ID="lblnolongitude" runat="server" Text="Longitude"></asp:Label>
        </td>
        <td style="width:80%">
            <asp:TextBox ID="txtnolongitude" runat="server"></asp:TextBox>
            <asp:RequiredFieldValidator ID="reqnolongitude" runat="server"
                ErrorMessage="Please Enter Longitude" ControlToValidate="txtnolongitude">*</asp:RequiredFieldValidator>
        </td>
    </tr>
    <tr>
        <td style="width:20%">
            <asp:Label ID="lblnolatitude" runat="server" Text="Latitude"></asp:Label>
        </td>
        <td style="width:80%">
            <asp:TextBox ID="txtnolatitude" runat="server"></asp:TextBox>
            <asp:RequiredFieldValidator ID="reqnolatitude" runat="server"
                ErrorMessage="Please Enter Latitude" ControlToValidate="txtnolatitude">*</asp:RequiredFieldValidator>
        </td>
    </tr>
    <tr>
        <td style="width:20%" valign="top">
            <asp:Label ID="lblhistory" runat="server" Text="History"></asp:Label>
        </td>
        <td style="width:80%">
            <asp:TextBox ID="txthistory" runat="server" TextMode="MultiLine" Height="176px"
                Width="350px"></asp:TextBox>
            <asp:RequiredFieldValidator ID="reqhistory" runat="server"
                ErrorMessage="Please Enter Latitude" ControlToValidate="txthistory">*</asp:RequiredFieldValidator>
        </td>
    </tr>
    <tr>
        <td colspan="2">
            &nbsp;<asp:ValidationSummary ID="vsummary" runat="server" Width="288px"
                Height="55px" />
        </td>
    </tr>
    <tr>
        <td colspan="2">
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <asp:Button ID="btnsubmit" runat="server" Text="Submit" onclick="Button1_Click" />
        </td>
    </tr>
</table>
</asp:Content>

C#
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class Default4 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        DataClass dtcs = new DataClass();
        //string history = txthistory.Text;
        //history = history
        txthistory.Text = txthistory.Text.Replace("'", "''");
        string str;
        str = "INSERT INTO city (nocityid,nostateid,vcname,vcdesc,nolongitude,nolatitude,vchistory) VALUES ('" + txtcityid.Text + "','" + ddstateid.SelectedItem.Value + "','" + txtname.Text + "','" + txtdesc.Text + "','"+ txtnolongitude.Text +"','"+ txtnolatitude.Text +"','"+ txthistory.Text +"')";
        dtcs.execqry(str);
        txtcityid.Text = "";
        txtname.Text = "";
        txtdesc.Text = "";
        txthistory.Text = "";
        txtnolatitude.Text = "";
        txtnolongitude.Text = "";
    }
}


Posted

Whenever you hit the Enter button a new line character get embedded in the string, Remove the character and store it in the database.
 
Share this answer
 
before saving to database you need to remove new lines from your text something like this
strYourText.replace(System.Environment.NewLine," ");


but i wonder why do you want to remove them since you might be interested to display that on other pages.. so why don't you display exactly what was entered in text area.. (with new lines)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900