Solved

How to get a handle to elements on html/aspx page using C#?

Posted on 2014-03-07
7
684 Views
Last Modified: 2014-04-08
Hello,

I'm about to design a 3 tier layer web application as:

database(sql server) <> middle tier (mvc/c#) <> front-end (js/html/css)

on a page I will be providing <canvas></canvas> so that user can sketch 2d objects using javascript. This will be a SVG sketch and I need to let user store that in a table (as xml).

My question is how can I get a handle to the canvas and what it lives on it after a sketch is done?

Thanks,
ak
0
Comment
Question by:akohan
  • 2
7 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 39913820
Get a "handle" from where? C#, or Javascript?
0
 

Author Comment

by:akohan
ID: 39918378
from front-end part where my canvas is. Yes from JS.
0
 

Author Comment

by:akohan
ID: 39931116
Anybody has idea how this can be done?
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 39977796
The canvas is just an element in the page, so you can grab it like:
var canvas  = document.getElementById("Your_Canvas_Id");

Open in new window

To get the contents of the canvas as a base64 encoded value that you can save to the database, you can use the toDataURL() method of the canvas object:
var data = canvas.toDataURL();

Open in new window

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

856 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