When I execute this code (inside .js) :
jQuery.fn.stickyNotes.createNote = function () {
var pos_x = 0;
var pos_y = 0;
var note_id = jQuery.fn.stickyNotes.notes.length + 1;
PageMethods.saveNote(note_id);
I need to save note_id value inside MSSQL database.
I put this on default.aspx (inside <body> I'm not sure if I'm right), to enable AJAX:
<pre lang="xml"><form id="form2" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
</form>
and for a method in default.aspx.cs
[System.Web.Services.WebMethod]
public static string saveNote(int note_id)
{
if (note_id == null || text.Length == 0)
return String.Empty;
SqlConnection conn = null;
try
{
string connection = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
conn = new SqlConnection(connection);
string sql = "INSERT INTO .....";
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.Parameters.AddWithValue("ID_Note", note_id);
conn.Open();
string contNm = Convert.ToString(cmd.ExecuteScalar());
return contNm;
I have this defined on <head>
<script type="text/javascript" src="script/jquery.stickynotes.js"></script>
By now I have two importante questions:
-
I still didnt compiled the code because I get the error that I have two forms with runat=server (I another one two login). How can I solve this problem? Can I put the script manager inside that form?
- If I do that my AJAX dont work. When I click add note nothing happens... previosly it works (it creates a new note/element). If I comment this line PageMethods.saveNote(note_id); it works again... It looks like that my JS stops working. Can you help me please ?
Thanks in advance.