Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Passing variable from ascx.cs file to javascript written in ascx

Posted on 2011-03-01
2
Medium Priority
?
1,191 Views
Last Modified: 2012-05-11
Hey !

I have this Javascript snippet in my style_block.ascx file:

<script type="text/javascript">

    if (!window.slider) var slider = {};
 
        slider.data += "[";
        var i = 1;
       
        while (i < max_dot) {
            slider.data += "{\"id\": \"slide-img-" + i + "\", \"client\": \"\", \"desc\": \"\"},";
            i++;
        }
        slider.data += "{\"id\": \"slide-img-" + i + "\", \"client\": \"\", \"desc\": \"\"}]";
   
</script>
Notice - Bold "max_dot variable

max_dot value is actually result of a sql query "Select count(*) from mantle" which I wrote in Style_block.ascx.cs

I am novice to Javascript, really a starter. Basically I want to access "max_dot" value between javascript tags. How can I do that ? Function ? Global variable ?

Thanks.

0
Comment
Question by:pratz09
2 Comments
 
LVL 5

Accepted Solution

by:
Kelmen earned 2000 total points
ID: 35013713
<%
//server asp code
int ServerCode_MaxDot = myhelper.GetMaxDotValueFromWherever();
%>

<script javascript>
...
var MaxDot = <%=ServerCode_MaxDot%>;
...
for (i < MaxDot ) ...
0
 

Author Closing Comment

by:pratz09
ID: 35013825
Thanks Kelmen !
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question