Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7040499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:55:32+00:00 2026-05-28T01:55:32+00:00

The last module of my chat script is passing values from C# code to

  • 0

The last module of my chat script is passing values from C# code to JavaScript and JavaScript will post values to the DIV. Before I used DataBinder but when using it directly C# code is taken by AJAX’s update panel. Now, I need a set of Array values to be passed via Timer Tick function to JavaScript. How can I pass Arrays from C# to JavaScript using <%= %>. A part of my code follows.

protected void Timer1_Tick(object sender, EventArgs e)
    {
        if (MyConnection.State == System.Data.ConnectionState.Open)
        {
            MyConnection.Close();
        }
        MyConnection.Open();
        OdbcCommand cmd = new OdbcCommand("Select message from messages where name=?", MyConnection);
        cmd.Parameters.Add("@email", OdbcType.VarChar, 255).Value = "human";
        OdbcDataReader dr = cmd.ExecuteReader();
        ArrayList values = new ArrayList();
        while (dr.Read())
        {
            string messagev = dr[0].ToString();
            // What should I do here?
        }
        MyConnection.Close();
    }

I don’t want values to directly to be sent to the DIV. First it must be sent to JavaScript and then it must go to DIV.

For more clarification

I need C# to retrieve data from backend and to pass that data to client side (i.e. JavaScript) from JavaScript it has to be forwarded to DIV layer.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T01:55:33+00:00Added an answer on May 28, 2026 at 1:55 am

    I am going to suggest the JQuery approach and get rid of the server-side timer. Using JQuery and the JQuery.Timer plugin: http://code.google.com/p/jquery-timer/ you can do this easier in my opinion and it will be nicer on the client end.

    In your aspx page you have the element to display output:

    <span id="status" style="display:none"></span>
    

    and also a reference to JQuery, JQuery.Timer.js, and then your code to call the c# web method.

    <script src="js/jquery-1.7.1.min.js" type="text/javascript"></script>
    <script src="js/jquery.timer.js" type="text/javascript"></script>
    <script>
        $(function () {
            var timer = $.timer(getMessage, 10000);
            timer.play();
        })
    
        function getMessage() {
            $.ajax({
                type: 'POST',
                contentType: 'application/json; charset=utf-8',
                url: 'message-service.asmx/getDBMessages',
                data: "{}",
                dataType: 'json',
                success: getMessageSuccess,
                error: getMessageError
            })
        }
    
        function getMessageError(jqXHR, textStatus, errorThrown) {
           $('#status').html(errorThrown).show();
        }
    
        function getMessageSuccess(data, textStatus, jqXHR) {
            $('#status').html(data.d).show();
        }
    </script>
    

    I would use a web-service for the server side db message retrieval:

    [WebService(Namespace = "http://site.com/service")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.Web.Script.Services.ScriptService]
    public class contact_service : System.Web.Services.WebService
    {
    
        [WebMethod]
        public string getDBMessages()
        {
            try
            {
     if (MyConnection.State == System.Data.ConnectionState.Open)
            {
                MyConnection.Close();
            }
            MyConnection.Open();
            OdbcCommand cmd = new OdbcCommand("Select message from messages where name=?", MyConnection);
            cmd.Parameters.Add("@email", OdbcType.VarChar, 255).Value = "human";
            OdbcDataReader dr = cmd.ExecuteReader();
            ArrayList values = new ArrayList();
            while (dr.Read())
            {
                string messagev = dr[0].ToString();
            }
            MyConnection.Close();
    return messagev;
            }
            catch (Exception ex)
            {
                return ex.Message;
            }
        }
    

    Hopefully this makes sense. I created a web-server (asmx) and created my server-side code to return a string. In the aspx markup I use JQuery to start a timer for 10 seconds and then an .ajax post to poll the service, retrieve the message and display it. No page refresh and much less hacky from my perspective.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to install this PHP module from NYTimes ( http://code.nytimes.com/projects/xslcache ) I unfortunately
In active_record/base.rb, module ActiveRecord you can see this code: delegate :find, :first, :last, :all,
I have an module to post predefined messages in my application, till last week
>>> import pylibmc Traceback (most recent call last): File <stdin>, line 1, in <module>
Last week we released Omniture's analytics code onto a large volume of web sites
Traceback (most recent call last): File <pyshell#80>, line 1, in <module> do_work() File C:\pythonwork\readthefile080410.py,
I'm using FiveStars module and I'm modifying the code. I need to get the
i am using BeautifulSoup module to select all href from html by this way:
I've spent last 2 days trying to launch examples from Boost.Python with the ImportError:
I'm looking to implement a chat room using PHP/Javascript (Jquery) with both group chat

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.