472,358 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,358 software developers and data experts.

how to get data from client-side assembly in one step?

I can get data from a client-side assembly to the server in two manual
steps, but I need to be able to do it in one step.

Step 1:
The user presses the manually coded "Step 1" button, which calls the
JavaScript function.
The function copies the data into a server textbox control.

Step 2:
The user presses the VS generated "Step 2" button, which calls the
server-side event handler "Button1_Click".
Button1_Click can read and thus process the contents of the server control.
<body MS_POSITIONING="GridLayout">

<OBJECT id="myControl1" height="288" width="312"
classid="ClientSideAssembly.dll#ClientSideAssembly .myControl"
name="myControl1" VIEWASTEXT>
</OBJECT>

<form id="Form1" name="Form1" method="post" runat="server" VIEWASTEXT>
<input onclick="doScript();" type="button" value="step 1" style="WIDTH:
100px; HEIGHT: 24px">
<asp:TextBox id="TextBox1" style="Z-INDEX: 101; LEFT: 11px; POSITION:
absolute; TOP: 400px"
runat="server" Width="359px"></asp:TextBox>
<asp:Button id="Button1" style="Z-INDEX: 103; LEFT: 375px; POSITION:
absolute; TOP: 400px"
runat="server" Text="Step 2" Width="82px"></asp:Button>
</form>

<script language="javascript">
function doScript()
{
// This line successfully uses the client-side assembly
// to read text from a client file and assign it to a server control,
// but this doesn't trigger the TextBox1_TextChanged event for that
server control.
Form1.TextBox1.value = myControl1.FileText;
}
</script>

</body>
Nov 17 '05 #1
1 2579
You have to connect both a client event handler and a server event
handler to the same button.
I recently implemented this functionality. Below is a test harness
that demonstrates how to pass a value from client to server using
either a server control (asp:button) or a client control
(HtmlInputButton)

(HTML)
************************************************** ******
<HTML>
<HEAD>
<title>ClientServerCrossover</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
<script language="javascript">
function client_func(source){
document.form1.hidden1.value = source;
//document.form1.hidden1.style.color
}
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="form1" method="post" runat="server">
<input ID="hidden1" runat="server" type="hidden">&nbsp;
<asp:Button id="aspButton" runat="server" style="Z-INDEX: 101;
LEFT: 43px; POSITION: absolute; TOP: 58px" Width="120px" Text="Use asp
button"></asp:Button>
<input ID="htmlInput" type="button"
onserverclick="EitherButton_Click" onclick="client_func('html
input');" runat="server" style="Z-INDEX: 102; LEFT: 210px; WIDTH:
104px; POSITION: absolute; TOP: 58px; HEIGHT: 24px" value="Use html
Input">
<asp:TextBox id="txtOutput" style="Z-INDEX: 103; LEFT: 16px;
POSITION: absolute; TOP: 116px" runat="server"
Width="333px"></asp:TextBox>
</form>
</body>

(codebehind)
************************************************** *********************
//the value(text) property can be assigned from client function for
later use by server code
protected System.Web.UI.HtmlControls.HtmlInputHidden hidden1;
//the client and server event handlers are specified in HTML
protected System.Web.UI.HtmlControls.HtmlInputButton htmlInput;
//the client event handler is added in Page_Load, the server event
handler in OnInit
protected System.Web.UI.WebControls.Button aspButton;
protected System.Web.UI.WebControls.TextBox txtOutput;

private void Page_Load(object sender, System.EventArgs e)
{
//if the control is a webcontrol (asp:) then client script event
handlers
//must be added at runtime
if (!IsPostBack)
aspButton.Attributes.Add("onclick", "client_func('asp button')");
}

public void EitherButton_Click(object sender, System.EventArgs e)
{
//both the htmlInput and the aspButton are wired up to use this
handler on postback
txtOutput.Text = ("value passed from client to server using " +
hidden1.Value.ToString());
}

override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
//add server event handler for server control
aspButton.Click += new
System.EventHandler(this.EitherButton_Click);
this.Load += new System.EventHandler(Page_Load);
}

- Fred W
"Jim Hammond" <jh******@postalinnovations.com> wrote in message news:<uA**************@TK2MSFTNGP10.phx.gbl>...
I can get data from a client-side assembly to the server in two manual
steps, but I need to be able to do it in one step.

Step 1:
The user presses the manually coded "Step 1" button, which calls the
JavaScript function.
The function copies the data into a server textbox control.

Step 2:
The user presses the VS generated "Step 2" button, which calls the
server-side event handler "Button1_Click".
Button1_Click can read and thus process the contents of the server control.
<body MS_POSITIONING="GridLayout">

<OBJECT id="myControl1" height="288" width="312"
classid="ClientSideAssembly.dll#ClientSideAssembly .myControl"
name="myControl1" VIEWASTEXT>
</OBJECT>

<form id="Form1" name="Form1" method="post" runat="server" VIEWASTEXT>
<input onclick="doScript();" type="button" value="step 1" style="WIDTH:
100px; HEIGHT: 24px">
<asp:TextBox id="TextBox1" style="Z-INDEX: 101; LEFT: 11px; POSITION:
absolute; TOP: 400px"
runat="server" Width="359px"></asp:TextBox>
<asp:Button id="Button1" style="Z-INDEX: 103; LEFT: 375px; POSITION:
absolute; TOP: 400px"
runat="server" Text="Step 2" Width="82px"></asp:Button>
</form>

<script language="javascript">
function doScript()
{
// This line successfully uses the client-side assembly
// to read text from a client file and assign it to a server control,
// but this doesn't trigger the TextBox1_TextChanged event for that
server control.
Form1.TextBox1.value = myControl1.FileText;
}
</script>

</body>

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Anon Email | last post by:
Hi people, I'm learning about header files in C++. The following is code from Bartosz Milewski: // Code const int maxStack = 16; class IStack
28
by: Act | last post by:
Why is it suggested to not define data members as "protected"? Thanks for help!
4
by: zhimin | last post by:
Hi, I'm writing a program to send large file(100m) through dotnet using TCPListener & TCPClient, I'm sending the file with a ask and response loop: 1. Client send a flag 1 to server indicate it...
3
by: Marc Gravell | last post by:
Kind of an open question on best-practice for smart-client design. I'd really appreciate anyones views (preferably with reasoning, but I'll take what I get...). Or if anybody has any useful links...
4
by: Schwarty | last post by:
I hope I posted this to the correct group. If not, please let me know and I will get it posted in the correct section. I have a web application developed in ASP.NET using C# for the code behind....
9
by: Macca | last post by:
Hi, I have a synchronous socket server which my app uses to read data from clients. To test this I have a simulated client that sends 100 byte packets. I have set up the socket server so...
2
by: Macca | last post by:
My app has an asynchronous socket server. It will have 20 clients connected to the server. Each client sends data every 500 millisecondsThe Connections once established will not be closed unless...
0
by: Macca | last post by:
Hi, I am writing an asychronous socket server to handle 20+ simulataneous connections. I have used the example in MSDN as a base. The code is shown at end of question. Each connection has a...
17
by: Timothy.Rybak | last post by:
Hello all, This is my first attempt at an application, so kid gloves are appreciated. I need to make a very simple form that only has a few elements. One is TraceCode - a text field that is...
1
by: quddusaliquddus | last post by:
Hi :D, I am sending data to server via TCP IP Connection. I am using a continuous loop at the server end - that accepts new clients and while streams can be read, it reads data stream. ...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it so the python app could use a http request to get...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.