Web User Control - fire function from client side

A

Ant

I'm building a Web user control that has several public functions. Can
I fire them from the client side? for example Javascript and an HTML
button
 
A

Andy Fish

yes

you just need to invoke a postback from javascript - you basically simulate
a click on a hidden button or something (google for details on how to do
this).
 
A

Ant

Thank you Andy.

I'm not that good with Javascript and I hope that I can get some help
here, this is what I have:

I created a Web User Control with the following:
Button1 (just in case I can not call the function directly)
Button2 (just in case I can not call the function directly)
Label1 (to display the status of my connection)
Connect (Function called when you 'click' on Button1)
Disconnect (Function called when you 'click' on Button2)

I placed my control in a ASPX page, with two HTML buttons:
<cc1:im_cicwebcontrol id="IM_CICWebControl1" ...
Button1 (calls a Javascript funtion (Connect))
Button2 (Calls a Javascript function (Disconnect))

When I run the ASPX page and 'view source' the page, I only see my
HTML buttons and my control items but with a different name:
for Button1 --> IM_CICWebControl1_Button1
for Button2 --> IM_CICWebControl1_Button2
for Label1 --> IM_CICWebControl1_Label1

I tried to call it like this in my Javascript:
var myObj = document.Form1;
alert (myObj.id);
myObj.IM_CICWebControl1_Button1; (does not work)
myObj.IM_CICWebControl1_Button1.Click; (does not work)
myObj.IM_CICWebControl1_Button1.Button1_Click; (does not work)

It does not work and I can not call also the functions...
Any Ideas???

Thanks
Ant
 
A

Andy Fish

I'm a bit confused about whether the Connect function is to run on the
client (i.e. javascript) or on the server (i.e. inside the form control). I
assume you mean on the server.

if it's on the server, you need to invoke the __doPostBack() function from
your javascript. the Page.GetPostBackEventReference function (on the server)
will generate the right parameters for the call.

Also, I think you are trying to solve 2 problems at once here: doing a
postback from javascript and integrating it with a user control. I would
suggest you get the javascript working without a user control before adding
that into the mix

HTH

Andy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top