Are you trying to change these database values on the fly? If so, you're going to probably need to do an OnTextChanged event for each field. Others here may have other suggestions but without seeing your entire project, I can only fathom a guess.
But label is not editable. You have to use a textbox or something like that. Try textbox without that contentEditable tag since textbox is editable by default.
NgJZliam.smi...
Member
37 Points
68 Posts
Re: Using html5 contentEditable to save to db
Apr 12, 2012 04:36 PM|LINK
I think the issue is that I am adding contentEditable="true" to an ASP Label which you can't really do.
I've tried doing this:
<h1 id="h1Test" contenteditable="true" runat="server"><asp:Label ID="h1" runat="server" CssClass="intro"></asp:Label></h1>
But I'm not sure how to get the h1Test assigned to a string variable in the code-behind file
bbcompent1
All-Star
33097 Points
8529 Posts
Moderator
Re: Using html5 contentEditable to save to db
Apr 12, 2012 04:45 PM|LINK
A label is not an editable control. use a text box.
NgJZliam.smi...
Member
37 Points
68 Posts
Re: Using html5 contentEditable to save to db
Apr 12, 2012 04:50 PM|LINK
contentEditable isn't "supported" by an ASP control. Which is why I think it isn't reading the changed value.
I think it has to be html controls but I'm not sure how I would use them in the code-behind.
bbcompent1
All-Star
33097 Points
8529 Posts
Moderator
Re: Using html5 contentEditable to save to db
Apr 12, 2012 05:07 PM|LINK
Are you trying to change these database values on the fly? If so, you're going to probably need to do an OnTextChanged event for each field. Others here may have other suggestions but without seeing your entire project, I can only fathom a guess.
NgJZliam.smi...
Member
37 Points
68 Posts
Re: Using html5 contentEditable to save to db
Apr 12, 2012 06:54 PM|LINK
Okay, this is what I have on my page entitled EditMyContent.aspx
<p> <asp:Button ID="saveBtn" runat="server" Text="Save Changes" onclick="saveBtn_Click" /> </p> </header> <div id="container"> <header> <asp:Image ID="userImage" runat="server" AlternateText="User" CssClass="image"/> <h1><asp:Label ID="h1" runat="server" CssClass="intro" contentEditable="true"></asp:Label></h1> </header>And this is everything I have in my saveBtn_Click function in the code-behind
protected void saveBtn_Click(object sender, EventArgs e) { string newName; string newIntro; string newEduc; string newWork; newName = h1.Text; newIntro = intro.Text; newEduc = educ.Text; newWork = employ.Text; string connectionInfo = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString; using (SqlConnection connection = new SqlConnection(connectionInfo)) { connection.Open(); SqlCommand myCommand = new SqlCommand("UPDATE simpleContent SET userName = @newName, infoContent = @newIntro, educContent = @newEduc, workContent = @newWork WHERE userID = @userName", connection); try { string username = HttpContext.Current.User.Identity.Name; myCommand.Parameters.AddWithValue("@userName", username.ToString()); myCommand.Parameters.AddWithValue("@newName", newName.ToString()); myCommand.Parameters.AddWithValue("@newIntro", newIntro.ToString()); myCommand.Parameters.AddWithValue("@newEduc", newEduc.ToString()); myCommand.Parameters.AddWithValue("@newWork", newWork.ToString()); myCommand.ExecuteNonQuery(); } catch { Response.Redirect("http://www.google.co.uk"); } connection.Close(); } }bbcompent1
All-Star
33097 Points
8529 Posts
Moderator
Re: Using html5 contentEditable to save to db
Apr 12, 2012 09:38 PM|LINK
But label is not editable. You have to use a textbox or something like that. Try textbox without that contentEditable tag since textbox is editable by default.