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?
LVL 1
ClivousAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
RosenetConnect With a Mentor Commented:
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.
0
 
RosenetCommented:
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.
0
 
ClivousAuthor Commented:
I discoverd my self
0
All Courses

From novice to tech pro — start learning today.