Solved

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

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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
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.

808 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