och såhär såg min funktion ut förut när jag använde mig av en textbox:
'=======================================
'## Uppdaterar vald nyhet i databasen ##
Dim tbox As TextBox
Dim EntryID, EntryHeader As String
EntryID = myNewsDatalist.DataKeys(e.Item.ItemIndex)
tbox = CType(e.Item.FindControl("header"), TextBox)
EntryHeader = tbox.Text
Dim objUpdateNews As myNewsClass = New myNewsClass()
Try
objUpdateNews.UpdateNewsEntry(EntryID, EntryHeader)
objUpdateNews = Nothing
myNewsDatalist.EditItemIndex = -1
LoadData()
Catch ex As Exception
Throw (ex)
End Try
Nu är frågan den hur jag ska göra för att kunna spara innehållet i min editor istället för ifrån min textbox?
Jag vet helt enkelt inte hur jag ska göra för att skicka med Editor1.EditorText som entryheader
såhär har dom gjort i det kodexemplet jag utgår ifrån
lblResult.Text = Editor1.EditorText
men det fungerar inte för mig ... får felet att Editor1.EditorText is not a member of system.web.ui.webcontrol ... antar att jag ska lägga till detta innan page_load
Protected WithEvents Editor1 As System.Web.UI.UserControl
Public MustInherit Class editor
Inherits System.Web.UI.UserControl
Protected WithEvents lblText2edit As System.Web.UI.WebControls.Literal
Protected WithEvents txtEditor As System.Web.UI.WebControls.TextBox
Protected WithEvents EditorView As System.Web.UI.HtmlControls.HtmlGenericControl
Protected WithEvents oDiv As System.Web.UI.HtmlControls.HtmlGenericControl
Public Property EditorText() As String
Get
Return txtEditor.Text
End Get
Set(ByVal Value As String)
lblText2Edit.Text = Value
txtEditor.Text = Value
End Set
End Property
Dim strSubmitScript As String
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
' Make clientside-script for formatting the text.
' On any change data must be copied from contenteditable-div to input-field.
' The scripts also focuses the contenteditable-div to make formatting possible and updates the input-field when done.
' RegisterClientScriptBlock is used to avoid multiple copies of the script and the editor control within a page.
' Find ClientId for the input-field and the div-field and make a clientside-script to do the copying
Dim InputClientId As String = FindControl("txtEditor").ClientID.ToString
Dim DivClientId As String = FindControl("oDiv").ClientID.ToString
Dim strEditorScript As String
strEditorScript = "<script language=""javascript"">"
strEditorScript += "function setFocus(){document.getElementById('" & DivClientId & "').focus();};"
strEditorScript += "function callFormatting(sFormatString){setFocus;document.execCommand(sFormatString);setFocus;};"
strEditorScript += "function copyTxt(){document.getElementById('" & InputClientId & "').value=document.getElementById('" & DivClientId & "').innerHTML;}"
strEditorScript += "</script" & ">"
' Register the script
' If already registered notify user that only one editor per page is allowed
If (Not Page.IsClientScriptBlockRegistered("EditorScript")) Then
Page.RegisterClientScriptBlock("EditorScript", strEditorScript)
' Ensure that any change is copied from contenteditable-div to input-field
oDiv.Attributes.Add("onactivate", "copyTxt();")
oDiv.Attributes.Add("ondeactivate", "copyTxt();")
Else
EditorView.Visible = False
End If
End Sub
End Class
Näe jag sedan ska uppdatera min nyhet från viewnews.ascx.vb så ska den ju plocka värdet ifrån textboxen "txtEditor" som ligger i min editor.ascx och sätta den till entryheader.
såhär ser koden för att uppdatera i databasen ut...
viewnews.ascx.vb
Dim tbox As TextBox
Dim EntryID, EntryHeader As String
EntryID = myNewsDatalist.DataKeys(e.Item.ItemIndex)
tbox = CType(e.Item.FindControl("txtEditor"), TextBox)
EntryHeader = tbox.Text
Dim objUpdateNews As myNewsClass = New myNewsClass()
Try
objUpdateNews.UpdateNewsEntry(EntryID, EntryHeader)
objUpdateNews = Nothing
myNewsDatalist.EditItemIndex = -1
LoadData()
Catch ex As Exception
Throw (ex)
End Try
Förtillfället får jag detta meddelande när jag försöker spara
Objektreferensen har inte angetts till en instans av ett objekt.
264 ms totalt · 4 externa anrop · v20260731065814-full.6fe65c25