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.CreateEmptyShap e("gisShap eTypePoint ");
}
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="doCreatePoi nt();"
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(co ntrolid);
gis.Editor.EndEdit();
gis.Editor.CreateEmptyShap e("gisShap eTypePoint ");
}
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?
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.CreateEmptyShap
}
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="doCreatePoi
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(co
gis.Editor.EndEdit();
gis.Editor.CreateEmptyShap
}
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I discoverd my self
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(
to create it.