Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET Javascript
Hi everybody,
 
Would you please help me. Do you know how I can draw a line with javascript in asp.net? Here is my code I can't make work:
 

<script type="text/JavaScript" src="jsDraw2D.js">
        function draw()
        {
            var gr = new jsGraphics(document.getElementById("some_div_id"));
            var col = new jsColor("Red");
            var pen = new jsPen(col, 2);
            var pt1 = new jsPoint(20, 30);
            var pt2 = new jsPoint(120, 230);
            gr.drawLine(pen, pt1, pt2);
        }
</script>
and here is my div in which i want to draw a line "onmousedown" event:
<div id="some_div_id" style="position:relative;width:600px;height:300px;background:Silver;" onmousedown="draw();"></div>
 
I was advised to download this &quot;jsDraw2D.js&quot; javascript library, but it didn't work, it was not even recognized by compiler as I saw.
 
So help me please if you can, I'm new at all in asp.net and jscript.
Posted 2-Dec-10 0:34am
Edited 2-Dec-10 0:44am
Slacker00775.8K
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi!
 
You have a very subtle error in your code. You need to include the jsDraw2D.js in a separate script tag that is included in the head section of your html like in my complete example below:
 
<html>
	<head>
		<title>Hallo???</title>
		<script type="text/javascript" src="./js/jsDraw2D.js"></script>
		<script type="text/javascript">
			function hello()
			{
				alert("Manfred was here!");
			}
			function draw()
			{
				var gr = new jsGraphics(document.getElementById("some_div_id"));
				var col = new jsColor("Red");
				var pen = new jsPen(col, 2);
				var pt1 = new jsPoint(20, 30);
				var pt2 = new jsPoint(120, 230);
				gr.drawLine(pen, pt1, pt2);
			}
		</script>
	</head>
	<body>
	and here is my div in which i want to draw a line "onmousedown" event:
	<div id="some_div_id" style="position:relative;width:600px;height:300px;background:Silver;border: 2px red solid" onmousedown="draw();">
	</div>
	</body>
</html>
</body></html>
 

Cheers
 
Manfred
  Permalink  
Comments
mmeliqyan at 3-Dec-10 1:15am
   
Thank you very much dear Manfred, now it works!
ManfredRBihy at 3-Dec-10 1:16am
   
Glad I could help you!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 George Jonsson 175
1 Kornfeld Eliyahu Peter 169
2 Zoltán Zörgő 139
3 PIEBALDconsult 130
4 OriginalGriff 120
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,107
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,342


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 2 Dec 2010
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100