Hi all,
i have a proble i need to get the client side javascript values in C# code at server side.
how can i pass those values?
i am using version 1.1, i kno thatwe can use callback events mechnisam in 2.0 or ajax ,apart from that how we can pass?
My problem is i need to stop the execution of the code based on after reciving values from the client
any ideas please???
Million thanks
Ram
Cheers
Ram MCP
![]() |
0 |
![]() |
Hello Ram,
a common approach is from javascript set an hidden field, then issue a postback. On the server-side, handle the post-back.
Feel free to go deeper in your question.
HTH. -LV
Julio P. Di Egidio
Software Analyst Programmer
=BUSINESS AND SCIENTIFIC=
=SOFTWARE DEVELOPMENT=
http://julio.diegidio.name
(Peace X Love] = [++1)
![]() |
0 |
![]() |
Hi LudovicoVan,
In programming we need to get that hidden variable through the reqest.form or request.querystring based on get or post procol we have used. is it am right or correct me.
My main problem is in my c# code i used RegisterClientScriptBlock to execute some javascrit code and the javascript function will reuturn some value based on that i need to stop execution or continnue, this how i can achieve please?
any exmaples will help alot..
Cheers
Ram MCP
![]() |
0 |
![]() |
ramana123:
> In programming we need to get that hidden variable through the reqest.form or request.querystring based on get or post procol we have used. is it am right or correct me.
That's an option (Request.Form i mean, as you are POST-ing back...). More commonly, make your input field runat-server, and you'll see it on the server-side as any other server control.
> My main problem is in my c# code i used RegisterClientScriptBlock to execute some javascrit code and the javascript function will reuturn some value based on that i need to stop execution or continnue, this how i can achieve please?
I'm afraid there is a misunderstanding here. Javascript executes client-side, while C# executes on the server. When you issue a RegisterXYZScript, that *will* output some javascript to the page upon rendering, and there you are on the client. From client you need to post-back to get to the server. You cannot intermix them...
For a very long running process, you might think of starting an async process on the server (i mean in another thread, or similar) and straight return your request to the client. Then the client will poll the server to see whether the background process has finished or not. This might be a self refreshing page, or an AJAX callback, etc. etc.
So, you are trying to do something not very trivial...
-LV
Julio P. Di Egidio
Software Analyst Programmer
=BUSINESS AND SCIENTIFIC=
=SOFTWARE DEVELOPMENT=
http://julio.diegidio.name
(Peace X Love] = [++1)
![]() |
0 |
![]() |
LudovicoVan,
do you mean we cannt stop the execution of the server code based on the cilent side javascript values?
can you explain me which code is executed first like server side or client side?
i have added a attribute like "onclick " to the button and also server side event onclick also added.
but when ever i ran the application first its executing the javascript and then going to sever side code.
can you let me know why the execution happens like this as per my view after execution of the server side the page will send to the client then the client side code will be executed.
could you please explain me this?
or any related links or articles would help me out.
Cheers
Ram MCP
![]() |
0 |
![]() |
Because that is the process known as post back communications.
It goes client side generates the page, client submits page (can be a submit, or an interaction with a web form object like a checkbox with auto-postback = true), then server generates the page on the server side (server side on_load event fired), then the server side handles any specific client side object events(like an onClick eveny), then the server posts the information to the client, and finally the client load the information from the server. Then the process repeats.
To break away from this fundamental form of communication is when you get into ajax (or known as Atlas in the microsoft world)
![]() |
0 |
![]() |
Ramana123,
Instead of using an <asp:button> try using an old fashion Html button
<input type="button" onclick="YourClick('MyButton','args')">
function YourClick(context, args)
{
//WhateverClientSideCodeYouWant
__doPostBack(context, args);
}
on the server
controlName = Request.Params.Get("__EVENTTARGET");
arguments = Request.Params.Get(__EVENTARGUMENT");
This will insure that your client script runs before the postback. You could also make a call to the callback function or create an XMLHTTP request object if you don't want to do a postback, but those are beyond the scope of your question.
![]() |
0 |
![]() |