Solved

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

Posted on 2011-03-01
2
1,129 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 500 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now