473,385 Members | 1,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 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 2660
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. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.