Link to home
Start Free TrialLog in
Avatar of Clivous
Clivous

asked on

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

Hi,

I have the following setup:

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

In MyUserControl.ascx I have the following Jave script:

    function doCreatePoint() {
        GIS.Editor.EndEdit();
        GIS.Editor.CreateEmptyShape("gisShapeTypePoint");
    }  

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

                        <table>                                
                           
                            <tr>
                               
                                <td class="ButtonCanvasHeight">
                                    <asp:ImageButton
                                        ID="ButtonPoint"
                                        runat="server"
                                        OnClientClick="doCreatePoint();"                            
                                        ImageUrl="~/Images/New.png"
                                        height="24px"
                                        width="24px" />
                                </td>

I also try the following Java script:

    function doCreatePoint() {
        var controlid = '<%= GIS.ClientID %>';
        var gis = document.getElementById(controlid);
        gis.Editor.EndEdit();
        gis.Editor.CreateEmptyShape("gisShapeTypePoint");
    }  

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?
Avatar of Rosenet
Rosenet

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.
ASKER CERTIFIED SOLUTION
Avatar of Rosenet
Rosenet

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Clivous

ASKER

I discoverd my self