Solved

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

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

929 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

15 Experts available now in Live!

Get 1:1 Help Now