string str = "<script type='text/javascript'>" +
"var lat=lon=-1;" +
"getLocation();" +
"function getLocation() {" +
"if (navigator.geolocation) {" +
"navigator.geolocation.getCurrentPosition(showPosition);" +
"}" +
"}" +
"function showPosition(position) {" +
"lat=position.coords.latitude;" +
"lon=position.coords.longitude;" +
"document.getElementById('<%=ltrLat.ClientID%>').innerHTML=lat;"+
"document.getElementById('<%=ltrLon.ClientID%>').innerHTML= lon;"+
"var x= document.getElementById('<%=ltrLat.ClientID%>').innerHTML;"+
"var y= document.getElementById('<%=ltrLon.ClientID%>').innerHTML;" +
"alert('lat='+x+'lon='+ y);" +
"}" +
"</script>";
ClientScriptManager cs = this.ClientScript;
cs.RegisterStartupScript(this.GetType(),"xyz", str);
ltrLatとltrLonは、クライアント側のaspラベルです。 また、ラベルが表示されません。 アラートが表示されません。以下のコードで何が問題になっていますか?
文字列sが使用されることはありません – Steffomio
注意を理解することを願っています
: '<%= ... %> 'は、レンダリングプロセスの一部として' .aspx'ファイル内でのみ認識されます。文字列リテラルや '.cs'ファイル内では置換されません。 –