Solved

c#/textarea - - issue with return from server//roundtrip

Posted on 2013-12-08
3
449 Views
Last Modified: 2013-12-10
the user enters a value and it makes it to the server and returns back to the client side....an alert box



everything works until it makes it back to the client from the server...an alert box is brought up showing that the values have attached to the textareas from the server...I clcik okay and the page returns and now the textareas are empty...what???



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

<!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 id="Head1" runat="server">
    <title>Untitled Page</title>
    <script src="http://code.jquery.com/jquery-1.5.min.js" language="javascript" type="text/javascript"></script> 
    <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

    <script language="javascript" type="text/javascript">

        var touched = false;
        var timer = null;
        var timeout = 4000; // 4 seconds

        var timer;
        var page_answer_ready;

        function after_answer() {

            if (page_answer_ready == true) {
                $("#TextArea2").text(answer);

            }


        }



   
        $(document).ready(function () {
            // Handler for .ready() called.

            if (page_answer_ready == true) {
                $("#TextArea2").text(answer);

            }

        });


    

        function startSearchTime(e) {
            window.clearTimeout(timer);
            var unicode = e.keyCode ? e.keyCode : e.charCode

            var timeToWait = 2000; // time in milliseconds;
            timer = window.setTimeout("doSearch()", timeToWait);
        }

        function doSearch() {
            window.clearTimeout(timer);
            // document.getElementById("Button1").click();
            CallSum()
        }


        var get_text;
        function CallSum() {
            alert("Hi there!");
            //////var txt1 = $get("</%= hotarea.ClientID %>");
            var txtresult = $get("txtSum");
            //var txtresult = "no value";
            get_text = $("#TextArea1").val();
            //PageMethods.Sum(txt1.value, OnCallSumComplete, OnCallSumError,txtresult);
            //PageMethods.Sum(txt1.value, OnCallSumComplete, OnCallSumError);
            PageMethods.Sum(get_text, OnCallSumComplete, OnCallSumError, txtresult);
        }

        var answer;
        var change_message;
        //function OnCallSumComplete(result, txtresult,methodName) {
        function OnCallSumComplete(result) {
            page_answer_ready = true;
            //Show the result in txtresult
            answer = result;
            //txtresult.value = result;
            alert(result);
            change_message = answer + "this message";
          $("#TextArea2").text(change_message);
         // document.getElementById('#TextArea2').value = result;
          
            $("label_answer").text(answer);
            alert(result);
        }

        function OnCallSumError(error, userContext, methodName) {
            // if (error !== null) {
            alert(error.get_message());
            // }
        }

        function $get(id) {
            return document.getElementById(id);
        }

// -->
</script>
    <style type="text/css">
        #TextArea1
        {
            width: 425px;
            height: 234px;
        }
        
         #TextArea2
        {
            width: 425px;
            height: 234px;
        }
        
        
           #hotarea
        {
            height: 192px;
            width: 424px;
        }
        
        #hotarea
        {
            height: 192px;
            width: 424px;
        }
    </style>
</head>
<body onload="after_answer()">
    <form id="form1" runat="server">
    <div>
    
        </div>
    <p>
        txtsum (Get a value to send to server)</p>
    <textarea id="TextArea1" run="server" cols="20" rows="2"></textarea>
    
    <p>
        &nbsp;</p>

        <br />
        <div id="Button_Click" onclick="CallSum()">
            <input type="submit" id="input_submit" value="Submit" />       
        </div>



    <p>
        hotarea (user input sent to server and now back)</p>
    
    <div id="div_TA2">
   
        <textarea id="TextArea2" cols="20" rows="2"></textarea>
        <input type="text" id="text_answer" />
        <label id="label_answer"></label>
    </div>
    
    <p>
        &nbsp;</p>
    <p>
        &nbsp;</p>
        <asp:scriptmanager ID="Scriptmanager1" runat="server" EnablePageMethods="true"></asp:scriptmanager>
    </form>
</body>
</html>

//===============
//===========
//===========
// code behind




using System.Data.SqlClient;
using System.IO;
//using System.Data.SqlClient.SqlDataAdapter;
//using System.Data.SqlClient.SqlConnection;
//using System.String;
//using System.StringComparison;
//using System.Text.StringBuilder;
//using System.Web.UI;
//using System.Web.UI.Page;
//using System.Web.UI.WebControls.TextBox;
//using System.Web.UI.WebControls;
//using System.Web.UI.ExtenderControl;
//using System.Random;
//using System.DateTime;
using System.Data.OleDb;
using System.Text;
using System.Data.Odbc;
using System.Data;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
//using System.Web.SessionState.HttpSessionState;

public partial class my_page : System.Web.UI.Page
{
    


    
    [System.Web.Services.WebMethod()]
     public static string Sum(String arg1)
    {
        // ' http://www.experts-exchange.com/Programming/Languages/.NET/Q_26878831.html
        // stackoverflow.com/questions/16775117/asp-net-scriptmanager-pagemethods-is-undefined


        arg1 = " made it to the server";

        return arg1;

    }


}

Open in new window

0
Comment
Question by:GlobaLevel
  • 2
3 Comments
 
LVL 10

Author Comment

by:GlobaLevel
ID: 39705248
anyone??
0
 
LVL 27

Accepted Solution

by:
Chinmay Patel earned 500 total points
ID: 39705410
Use ASP.Net TextBox control and set its TextMode to Multiline.

<asp:TextBox TextMode="Multiline" id="TextAread" />

Open in new window

0
 
LVL 10

Author Closing Comment

by:GlobaLevel
ID: 39710532
good
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

766 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question