Solved

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

Posted on 2013-12-08
3
448 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

831 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