Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / June 2007

Tip: Looking for answers? Try searching our database.

Mixing javascript and ASP.net code

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Aussie Rules - 14 Jun 2007 22:48 GMT
Hi.

I am using Live Earth SDK, and have very little Javascript knowledge, but I
need to insert values into a Javascript function, where the vales are in the
ASP.net VB code.

The javascript function is below, but I need to replace the value
(47.6, -122.33) with variables in the code behind page that I get from my
SQL 2000 database.

Is there a way to do this ?

Thanks

function GetMap()
        {
           map = new VEMap('myMap');
           map.LoadMap(new VELatLong(47.6, -122.33), 10 ,'h' ,false);
        }
Milosz Skalecki [MCAD] - 15 Jun 2007 00:37 GMT
Hi Aussie,

I hope you are well. There are two ways of doing it.
1. Use methods offered by ClientScriptManager class
i.e.

protected void Page_Load(object sender, EventArgs e)
{

    // these variables should be set to values
    // retreived from database
    double x = 47.6;
    double y = -122.33;

    if (!ClientScript.IsClientScriptBlockRegistered(this.GetType(), "mapScript"))
    {

        string script =
            "<script type=\"text/javascript\">\n" +
            "function GetMap() {{\n" +
            "    var map = new VEMap('myMap');\n" +
            "    map.LoadMap(new VELatLong({0}, {1}), 10 ,'h' ,false);\n" +
            "}}\n" +
            "</script>";

        ClientScript.RegisterClientScriptBlock(
            this.GetType(),
            "mapScript",
            String.Format(script, x, y));
    }
}

or storing retreived values in properties and then using <%%> code block on
the aspx page:

-- code behind/beside --

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        // populate with values from database
        XCoordinate = 47.6;
        YCoordinate = -122.33;
    }
}

// i used viewstate in order to
// not to make database roundtrips on postbacks
protected double XCoordinate
{
    get
    {
        object value = ViewState["XCoordinate"];
        return value == null ? 0.0d : (double)value;
    }
    set
    {
        ViewState["XCoordinate"] = value;
    }
}

protected double YCoordinate
{
    get
    {
        object value = ViewState["YCoordinate"];
        return value == null ? 0.0d : (double)value;
    }
    set
    {
        ViewState["YCoordinate"] = value;
    }
}

-- end code behind/beside --

-- aspx page code --

<script type="text/javascript">
       
function GetMap()
{
    map = new VEMap('myMap');
    map.LoadMap(new VELatLong(<%= XCoordinate %>, <%= YCoordinate %>), 10 ,'h'
,false);
}

</script>
-- end aspx page code --

Hope it helps

Signature

Milosz

> Hi.
>
[quoted text clipped - 15 lines]
>             map.LoadMap(new VELatLong(47.6, -122.33), 10 ,'h' ,false);
>          }
Göran Andersson - 15 Jun 2007 00:41 GMT
> Hi.
>
[quoted text clipped - 15 lines]
>            map.LoadMap(new VELatLong(47.6, -122.33), 10 ,'h' ,false);
>         }

Put a Literal control where you want the value, and set the Text
property of the control in code behind.

Signature

Göran Andersson
_____
http://www.guffa.com

bruce barker - 15 Jun 2007 00:59 GMT
function GetMap()
         {
            map = new VEMap('myMap');
            map.LoadMap(new VELatLong(<%=codebehindfunc1()%>,
            <%=codebehindfunc2()%>),
            10 ,'h' ,false);
         }

-- bruce (sqlwork.com)

> Hi.
>
[quoted text clipped - 15 lines]
>            map.LoadMap(new VELatLong(47.6, -122.33), 10 ,'h' ,false);
>         }

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.