0

I want to pass a value to this JavaScript from the database (using datareader in asp.net(C#)).

The script is from http://www.dynamicdrive.com/dynamicindex14/leftrightslide.htm

I need to set a pass value in the below line:

leftrightslide[cnt] = '<a href="MYWEBPAGE"><img src="MYIMAGE FRM DATABASE.gif" border=1></a>';
cnt++;

So the value of the datareader would be passed into the JavaScript array.

3 Answers 3

1

See following:
http://www.velocityreviews.com/forums/t76971-populating-javascript-array-from-vb-net.html
Create string from serverside using datareader and register it.

OR

use RegisterArrayDeclaration(arrayName, arrayValue) from server side. See following for this:
http://msdn.microsoft.com/en-us/library/aa479302.aspx

Sign up to request clarification or add additional context in comments.

Comments

0

You can use a webservice

1 Comment

I have copied this script in my default.aspx page and my coding for datareader is object objProd = DProducts.getAllProducts(); ProdRD = (SqlDataReader)objProd; ProdRD.Read();
0

you have to use the script manager http://msdn.microsoft.com/en-us/library/system.web.ui.page.clientscript.aspx for doing this. check the link it will help.

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
  public void Page_Load(Object sender, EventArgs e)
  {
    // Define the name and type of the client scripts on the page.
    String csname1 = "PopupScript";
    Type cstype = this.GetType();

    // Get a ClientScriptManager reference from the Page class.
    ClientScriptManager cs = Page.ClientScript;

    // Check to see if the startup script is already registered.
    if (!cs.IsStartupScriptRegistered(cstype, csname1))
    {
        StringBuilder cstext1 = new StringBuilder();
        cstext1.Append("<script type=text/javascript> alert('Hello World!') </");
        cstext1.Append("script>");

        cs.RegisterStartupScript(cstype, csname1, cstext1.ToString());
    }
  }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>RegisterStartupScript</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    </div>
    </form>
</body>
</html>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.