Access a server side component from Java script in a webUserControl.ascx


I have the following setup:

MasterPage.Master -> MyPage.aspx -> MyUserControl.ascx

In MyUserControl.ascx I have the following Jave script:

    function doCreatePoint() {

My problem is dat this Jave script displays a error (can't find GIS) when I call it from the following button:

                                <td class="ButtonCanvasHeight">
                                        width="24px" />

I also try the following Java script:

    function doCreatePoint() {
        var controlid = '<%= GIS.ClientID %>';
        var gis = document.getElementById(controlid);

But then I get a error with the message 'the editor is empty'. I think that the GIS component is not loaded when i call this Java script. When I try the whole setup directly in a aspx page without a masterpage then it works.

How can I make this to work?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi there,

It sounds like ASP doesn't know the ClientID of the GIS (I assume some server control?) when your JavaScript is executing.
One way to do this is to access it programmatically.

In your Page_Load() method on the server you can access any ClientID's and send them to client via your preferred method:

protected void Page_Load(object sender, EventArgs e)
     string sGIDClientID = GIS.ClientID;

    // do something with the clientID
    Literal1.Text = sGIDClientID;
    HiddenTextField1.Text = sGIDClientID;
    // etc...

You can even create the JavaScript on the server side and call
RegisterClientScriptBlock("myScript", sScript);
 to create it.
I spent time attempting to help the post's author and wrote up a potential solution for other users of the site who encounter this problem to see.

I believe it's still very valuable to have as a searchable resource.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ClivousAuthor Commented:
I discoverd my self
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Apple Software

From novice to tech pro — start learning today.