asp.net - How to set a img in my aspx page through javascript? -
maybe sounds stupid, can't figure out how set <img>
code in .aspx page throught javascript.
my code far:
<%@ page language="vb" masterpagefile="~/masterpage.master" autoeventwireup="false" codefile="teste.aspx.vb" inherits="teste" %> <asp:content id="content1" contentplaceholderid="contentplaceholder1" runat="server"> latitude: <asp:textbox id="nr_latitudetextbox" runat="server" maxlength="12" /> <br /> longitude: <asp:textbox id="nr_longitudetextbox" runat="server" maxlength="12" /><br /> <asp:button id="cmb_mapa" runat="server" text="mapa" onclick="cmb_mapa_click"/><br /> <script language="javascript" type="text/javascript"> function fonte(lat, lon) { var src = "http://maps.google.com/maps/api/staticmap?center=lat,lon&zoom=8&size=540x280&maptype=roadmap&sensor=false"; testando("http://maps.google.com/maps/api/staticmap?center=lat,lon&zoom=8&size=540x280&maptype=roadmap&sensor=false", 540, 280, "mapa"); } function testando(src, width, height, alt) { var img = document.createelement("img"); img.src = src; img.width = width; img.height = height; img.alt = alt; document.body.appendchild(img); } </script> <div id="img"> </div> </asp:content>
partial class:
partial class teste inherits system.web.ui.page protected sub cmb_mapa_click(byval sender object, byval e system.eventargs) handles cmb_mapa.click page.clientscript.registerstartupscript(me.gettype(), "testando", "testando(" & nr_latitudetextbox.text & "," & nr_longitudetextbox.text & ");", true) end sub end class
testando
first parameter image url , you're not providing it.
it seems want call fonte
, not testando
on registerstartupscript
. that's method takes latitude , longitude parameters.
edit
change
var src = "http://maps.google.com/maps/api/staticmap?center=lat,lon&zoom=8&size=540x280&maptype=roadmap&sensor=false" testando("http://maps.google.com/maps/api/staticmap?center=lat,lon&zoom=8&size=540x280&maptype=roadmap&sensor=false", 540, 280, "mapa");
by
var src = "http://maps.google.com/maps/api/staticmap?center=" + lat + "," + lon + "&zoom=8&size=540x280&maptype=roadmap&sensor=false"; testando(src, 540, 280, "mapa");
fixed 2 things:
1) weren't using lat
, lon
parameter map url fixed src
building
2) added src
parameter testeando
since weren't using it
Comments
Post a Comment