Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

Trying to call javascript not sure I can do what I want

$
0
0

I am trying to call javascript from the code behind.

<%@ Page language="c#" Inherits="tsiWebSite.WebForm1" CodeFile="Main.aspx.cs" %><%@ Import Namespace="my.assembly.stuff" %><html><head><script type="text/JavaScript" src="jscript/jswindowCallBack.js"></script></head><body><form id="Form1" method="post" runat="server"></form><div id="docBody"></div><script type="text/JavaScript">
addWindow('Futures - CL',       'futureview.aspx?futures=3');
addWindow('Futures - NG',       'futureview.aspx?futures=12');
addWindow('Pick View - General','open.aspx');</script></body></html>

I have cut down the actual Main.aspx file. It does not have any controls. The javascript file (jswindowCallBack.js) has the function addWindow() which creates iframe's and that is where the aspx code files are located.

It also has the function lib_setdata( str1, str2, str3 )

It is that function I am trying to invoke in the code below

/* Main.aspx.cs */

namespace tsiWebSite
{
	public partial class WebForm1 : System.Web.UI.Page
	{
		private Socket m_socket;

		protected void Page_Load(object sender, System.EventArgs e)
		{
			// socket connects here.
			WaitForDataTSI( null, m_socket );
		}


		public void WaitForDataTSI(IAsyncResult ar, System.Net.Sockets.Socket socket)
		{
			try
			{
				SocketControl socketControl;
				if (ar == null)
				{
					socketControl = new SocketControl();
				}
				else
				{
					socketControl = (SocketControl)ar.AsyncState;
				}
				socketControl.m_socket = socket;

				m_socket.BeginReceive(socketControl.buffer, 0, SocketControl.BUFFER_SIZE, 0,
									  new AsyncCallback( OnDataReceivedTSI ),
									  socketControl);
			}
			catch (SocketException /*se*/)
			{
				//MessageBox.Show(se.Message); 
			}
		}

		/* This function actually does more than is shown here, such as coping with half or one and half messages */  

		public void OnDataReceivedTSI(IAsyncResult ar)
		{
			try
			{
				SocketControl state = (SocketControl)ar.AsyncState;
				Socket s = state.m_socket;

				int read = s.EndReceive(ar);

				byte[] message = new byte[state.m_Offset + read];
				System.Buffer.BlockCopy(state.buffer, 0, message, 0, read);

				String sLine = System.Text.UTF8Encoding.UTF8.GetString(message);
				String[] f = sLine.Split('|');

/////////////////	This is where I have my problem.

				//String sExecute = "<script type=\"text/javascript\">lib_setdata('" + f[0] + "','" + f[1] + "','" + f[2] + "');</script>";
				String sExecute = "lib_setdata('" + f[0] + "','" + f[1] + "','" + f[2] + "');";

				System.Diagnostics.Debug.WriteLine(sExecute);

				//ClientScript.RegisterClientScriptBlock( this.GetType(), "invoke",  sExecute, false );
				//ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "invoke", sExecute, true);
				ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "invoke", sExecute, true);
				//ScriptManager.RegisterStartupScript( this, this.GetType(), "invoke", sExecute, true );

/////////////////

				WaitForDataTSI(read>0?ar:null, s);	// amended for code read
			}
			catch (ObjectDisposedException)
			{
				System.Diagnostics.Debugger.Log(0, "1", "\nOnDataReceivedTSI: Socket has been closed\n");
			}
			catch (SocketException /*se*/)
			{
				//MessageBox.Show(se.Message);
			}

		}

		public class SocketControl
		{
			public Socket m_socket = null;
			public const int BUFFER_SIZE = 1024;
			public byte[] buffer = new byte[BUFFER_SIZE];
			public byte[] cache; 
			public int m_Offset = 0;
		}
	}
}

 

I do not understand the registering of script blocks at all.

In the case of Java an applet via JSObject can get at the DOM window and then Call my javascript function lib_setdata()

I was hoping for the same in Active Server Pages

Any ideas please folks?


Viewing all articles
Browse latest Browse all 5678


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>