Solved

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

Posted on 2011-03-01
2
1,161 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

 Watch the Recording: Learning MySQL 5.7

MySQL 5.7 has a lot of new features. If you've dabbled with an older version of MySQL, it is definitely worth learning.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
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…
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

636 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