locked
Insert text area data to sq=l database RRS feed

  • Question

  • User810354248 posted

    In my asp.net+vb+sql web i have a dashboard for creating notes. I am planning to have users can type note title then enter text in text area and have another field for inserting images/ video/ mp3

    I am using the below text editor in my asp.net form 

    https://github.com/suyati/line-control/blob/master/demo.html

    when i change 

    <textarea id="txtEditor"  ></textarea> 

    to

    <textarea id="txtEditor"  runat="server" ></textarea> 

    the entire text editor control disappears and the textarea shows as  a textbox only

    Complete code

    <div class="container-fluid">
    			<div class="row">    
    				<div class="container">
    					<div class="row">
    						<div class="col-lg-12 nopadding">
    							<textarea id="txtEditor" ></textarea> 
    						</div>
    					</div>
    				</div>
    			</div>
    		</div>
    		<div class="container-fluid footer">

    how can i insert the data of textarea to sql database

    I want to insert the data of text area to the sql database

    Sunday, September 10, 2017 1:19 PM

Answers

  • User-707554951 posted

    Hi Baiju EP,

    I test your code and add ruant="server" to textarea, but it works fine.

    And you also could use textbox like this:

    <asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine" Columns="10" Rows="2"></asp:TextBox>

    The following working code is about inserting data into database:

    In ASPX:

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js">
        </script>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js" type="text/javascript"></script>
        <script src="Scripts/editor.js"></script>
        <script>
            $(document).ready(function () {
                $("#txtEditor").Editor();
            });
            function displayText() {
                $.ajax({
                    type: "POST",
                    url: "insert.aspx/GetCurrentTime",
                    data: '{ name: "' + $(".Editor-editor")[0].innerText+'" }',
                    //data: '{ name: "Velen" }',
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: OnSuccess,
                    failure: function (response) {
                        alert(response.d);
                    }
                });
            }
            function OnSuccess(response) {
                alert(response.d);
            }
        </script>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" />
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css" />
        <link href="CSS/editor.css" rel="stylesheet" />
    <div class="container-fluid">
                <div class="row">
                    <div class="container">
                        <div class="row">
                            <div class="col-lg-12 nopadding">
                                <%--<asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine" Columns="10" Rows="2"></asp:TextBox>--%>
                                <textarea id="txtEditor" runat="server"></textarea>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <button type="button" onclick="displayText()">Save</button>
            <div class="container-fluid footer">
            </div>

    In code behind:

    [System.Web.Services.WebMethod]
            public static string GetCurrentTime(string name)
            {
                string mystr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
                SqlConnection myConn = new SqlConnection(mystr);
                myConn.Open();
                string sqlStr = @"Insert into [User] (name) values (@name)";
                SqlCommand cmd = new SqlCommand(sqlStr, myConn);
                cmd.Parameters.AddWithValue("@name", name);
                cmd.ExecuteNonQuery();
                myConn.Close();
                return "succ";
            }

    Output:

    Best regards

    Cathy

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 11, 2017 9:13 AM

All replies

  • User475983607 posted

    In ASP web Forms a textarea is created by setting the TextBox's attribute TextMode="multiline".  

    <asp:TextBox id="Editor" TextMode="multiline" Columns="100" Rows="10" runat="server" />

    I suggest that you contact LineControl support using the API.

    Sunday, September 10, 2017 2:23 PM
  • User-707554951 posted

    Hi Baiju EP,

    I test your code and add ruant="server" to textarea, but it works fine.

    And you also could use textbox like this:

    <asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine" Columns="10" Rows="2"></asp:TextBox>

    The following working code is about inserting data into database:

    In ASPX:

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js">
        </script>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js" type="text/javascript"></script>
        <script src="Scripts/editor.js"></script>
        <script>
            $(document).ready(function () {
                $("#txtEditor").Editor();
            });
            function displayText() {
                $.ajax({
                    type: "POST",
                    url: "insert.aspx/GetCurrentTime",
                    data: '{ name: "' + $(".Editor-editor")[0].innerText+'" }',
                    //data: '{ name: "Velen" }',
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: OnSuccess,
                    failure: function (response) {
                        alert(response.d);
                    }
                });
            }
            function OnSuccess(response) {
                alert(response.d);
            }
        </script>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" />
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css" />
        <link href="CSS/editor.css" rel="stylesheet" />
    <div class="container-fluid">
                <div class="row">
                    <div class="container">
                        <div class="row">
                            <div class="col-lg-12 nopadding">
                                <%--<asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine" Columns="10" Rows="2"></asp:TextBox>--%>
                                <textarea id="txtEditor" runat="server"></textarea>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <button type="button" onclick="displayText()">Save</button>
            <div class="container-fluid footer">
            </div>

    In code behind:

    [System.Web.Services.WebMethod]
            public static string GetCurrentTime(string name)
            {
                string mystr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
                SqlConnection myConn = new SqlConnection(mystr);
                myConn.Open();
                string sqlStr = @"Insert into [User] (name) values (@name)";
                SqlCommand cmd = new SqlCommand(sqlStr, myConn);
                cmd.Parameters.AddWithValue("@name", name);
                cmd.ExecuteNonQuery();
                myConn.Close();
                return "succ";
            }

    Output:

    Best regards

    Cathy

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 11, 2017 9:13 AM