Sunday, March 11, 2012

Passing client side to server side using hidden field

Can youuse __doPostBack() to trigger a partial postback at the same time the hidden TextBox is updated, from JavaScript?


I made a mistake in my original post I meant to say "without post back"


A page method might be a good way to do it, depending on what you're trying to do.


I took a look at pagemethods but they seem to be used for accessing C# method from javascript I need to do the opposite. plus pagemethods are limited to static methods.

At the risk of complicating the question here's my situation. I have an activex object that has a javascript interface. The activex causes a javascript function to fire and the function receives some data from the activex control.

I need to access the data from the Javascript function some how from C# codebhind. I was hoping I could access it from a C# code behind using something like or unlike this:

function GetData(someinput) //someinput will be coming from the activex object

{

return "Here's some output:" + someinput;

}

It would be nice if I were able to call that function from c# codebehind:

public string GetOutput()
{
string Output = GetData();

return Output;
}

Currently I am populating a server side text box from javascript and I am trying to access it everytime it changes with the TextChange event but that event requires user interaction to set focus out side the textbox.

I am in desperate need of a solution.

Thanks, Justin.


Unfortunately, since the HTTP protocol is stateless, you can't directly initiate client side actions from the server side.

If this ActiveX control is something you have the ability to modify, you could have it maintain bidirectional contact with the server or have it poll the server for updates to whatever would cause you to update this hidden TextBox.

If you need a JavaScript solution, probably the best bet is something like this: http://encosia.com/index.php/2007/07/25/display-data-updates-in-real-time-with-ajax/

Using that, you could poll the server directly for whatever condition requires interaction with the ActiveX control. Page methods are light weight enough that you can poll pretty frequently and it's not a huge burden (depending on what happens in the method, of course).

No comments:

Post a Comment