Groups | Blog | Home
all groups > asp.net webcontrols > july 2004 >

asp.net webcontrols : Accessing an embedded UserControl "<object" in javascript



Mombiatch
7/28/2004 6:00:40 PM
Hi

I'm trying to set a property on a UserControl that I've embedded in my
ASP.NET web page. At first, I had the following in the <form> section:

<object id="mediaclient"
classid="mediaclient.dll#NeuralFramework.MediaBroker.MediaClient"></object>

When I tried to use custom javascript to set a property on 'mediaclient', I
put the following in Page_Load:

this.RegisterStartupScript("setGUID", "<script
language=javascript>mediaclient.strFileGUID=\"6a35ba9b-bbde-4678-9057-fb15c7
a685b8\";var gControl = mediaclient;alert(gControl.strFileGuid);</script>");

With the object in the form section, this bombs out saying that mediaclient
is null. So I tried putting it in the <body> section, before the <form>
section, and this works nicely, I can set the property and then use it when
I call functions of the UserControl. I then tried to put it after the <form>
section, but still in the <body> section, as I'd like it to be on the bottom
of the page. Unfortunately, it bombed out there too, saying that mediaclient
was once again null. Does anyone have any advice on getting around this or a
different strategy to suggest?

Thanks
Joe

Mombiatch
7/30/2004 9:31:02 AM
I have the solution to this problem, right in my office :-P One embeds it in
the form section, and then any JavaScript calls are made with the name
qualified with the form's id, like Form1.mediaclient.strFileGuid.

Joe

[quoted text, click to view]

AddThis Social Bookmark Button