Thursday, July 7, 2011

Passing parameters to javascripts from code behind

Default.aspx
------------------
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>    
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:Label ID="lblValue" runat="server"></asp:Label>
    <asp:HiddenField ID="hdn1" runat="server" />
    </div>
    </form>
</body>
</html>
Default.aspx.cs
------------------
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Random rand = new Random((int)DateTime.Now.Ticks);
        
        hdn1.Value =  "ooty";
        Response.Write("<script> alert('" + hdn1.Value +"');</script>");
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        sb.Append("<script type='text/javascript'>");
        sb.Append("var ws_wsid = '9ad5fdccd9224b53a60db7369ab5b733';");
        sb.Append("var ws_address ='" + hdn1.Value + "' ;var ws_width = '600';var ws_height = '460';var ws_layout = 'horizontal';var ws_transit_score = 'true';");
        sb.Append("var ws_commute = 'true';");
        sb.Append("var ws_map_modules = 'all';");
        sb.Append("</script><style type='text/css'>#ws-walkscore-tile{position:relative;text-align:left}#ws-walkscore-tile *{float:none;}#ws-footer a,#ws-footer a:link{font:11px/14px Verdana,Arial,Helvetica,sans-serif;margin-right:6px;white-space:nowrap;padding:0;color:#000;font-weight:bold;text-decoration:none}#ws-footer a:hover{color:#777;text-decoration:none}#ws-footer a:active{color:#b14900}</style><div id='ws-walkscore-tile'><div id='ws-footer' style='position:absolute;top:442px;left:8px;width:588px'><form id='ws-form'><a id='ws-a' href='http://www.walkscore.com/' target='_blank'>What's Your Walk Score?</a><input type='text' id='ws-street' style='position:absolute;top:0px;left:170px;width:386px' /><input type='image' id='ws-go' src='http://cdn.walkscore.com/images/tile/go-button.gif' height='15' width='22' border='0' alt='get my Walk Score' style='position:absolute;top:0px;right:0px' /></form></div></div><script type='text/javascript' src='http://www.walkscore.com/tile/show-walkscore-tile.php'></script>");
         sb.ToString();
         Response.Write(sb.ToString());
    }
}

walkscore

0 comments:

Post a Comment