Saving the text value to a SQL Server database

Last post 09-25-2008, 9:06 AM by DarkStar. 5 replies.
Sort Posts: Previous Next
  •  09-17-2008, 2:13 PM 44023

    Saving the text value to a SQL Server database

    Hi I have the Cute Editor installed in Dot Net Nuke. I have a SQl Server database tied to the app.
    The problem I have is that it is not saving the text in it to the database.  But If I put data into the Database it does read that data.

    I did some research on line and found any examples that weer similar had other issues in them that added several bits of complexity.
    I'm sure my situation is easy but I'm new to using the editor so I'm hoping it is something I have missed or not sure what terms to search for.
     
    Here is a snippet where I try to add the text of the editor to a parameter of a stored procedure that updates the data:
    with cmd
     
     .Parameters.Add(New SqlParameter("@PortalSettingsDealerImageURL", SqlDbType.VarChar))
                    .Parameters("@PortalSettingsDealerImageURL").Value = Server.HtmlDecode(EditorImageOwner.Text)
    end With

    This part works as expected, it reads the data from the database and displays it OK:
    EditorImageOwner.Text = ds.Tables(0).Rows(0).Item("PortalSettingsDealerImageURL")
  •  09-17-2008, 6:10 PM 44027 in reply to 44023

    Re: Saving the text value to a SQL Server database

    Please change:
     
     .Parameters("@PortalSettingsDealerImageURL").Value = Server.HtmlDecode(EditorImageOwner.Text)
     
    to:
     
     .Parameters("@PortalSettingsDealerImageURL").Value = Server.HtmlDecode("Hello World")
     
    Then try again.
     
    If it is still not working, please post more code.

    asp.net Chat http://cutesoft.net/ASP.NET+Chat/default.aspx
    Web Messenger: http://cutesoft.net/Web-Messenger/default.aspx
    asp.net wysiwyg editor: http://cutesoft.net/ASP.NET+WYSIWYG+Editor/default.aspx
    asp wysiwyg html editor: http://cutesoft.net/ASP
    asp.net Image Gallery: http://cutesoft.net/ASP.NET+Image+Gallery/default.aspx
    Live Support: http://cutesoft.net/live-support/default.aspx

  •  09-19-2008, 9:46 AM 44112 in reply to 44027

    Re: Saving the text value to a SQL Server database

    Hi.  Thanks for the reply.
     
    Origional code:

    .Parameters("@PortalSettingsImageLogoURL").Value = Server.HtmlDecode(EditorImageLogo.Text)
    .Parameters("@PortalSettingsDealerImageURL").Value = Server.HtmlDecode(EditorImageOwner.Text)
     
    result: both stored an empty string in the Database, overriding what was there before.
     
    I have two editors and I made the changes as follows :
    .Parameters("@PortalSettingsImageLogoURL").Value = Server.HtmlDecode("Hello World!")
    .Parameters("@PortalSettingsDealerImageURL").Value = Server.HtmlDecode("Hello World!")
     
    result: both saved the value "Hello World!" in the database
     
  •  09-19-2008, 7:38 PM 44124 in reply to 44112

    Re: Saving the text value to a SQL Server database

    Now try:
     
     .Parameters("@PortalSettingsDealerImageURL").Value = Server.HtmlDecode("Hello World" & EditorImageOwner.Text))
     
    If you get "Hello World" only, for some reasons, the Text property is empty when extracting the content from editor.
     
    When debugging, you need to focus on this part.
     
    Maybe you forget IsPostBack event, and set the editor value to empty automatically.
     
    Public Sub Page_Load(sender As object, e As System.EventArgs)
     
      If Page.IsPostBack Then
          Literal1.Text = "<h3>The HTML you typed is...</h3><br>" 
          Literal1.Text += Server.HtmlEncode(Editor1.Text)
      Else
           Editor1.Text = "Type Here"
      End If
      'This will cause problem
       Editor1.Text = "Some code"
     End Sub

    asp.net Chat http://cutesoft.net/ASP.NET+Chat/default.aspx
    Web Messenger: http://cutesoft.net/Web-Messenger/default.aspx
    asp.net wysiwyg editor: http://cutesoft.net/ASP.NET+WYSIWYG+Editor/default.aspx
    asp wysiwyg html editor: http://cutesoft.net/ASP
    asp.net Image Gallery: http://cutesoft.net/ASP.NET+Image+Gallery/default.aspx
    Live Support: http://cutesoft.net/live-support/default.aspx

  •  09-22-2008, 9:09 AM 44160 in reply to 44124

    Re: Saving the text value to a SQL Server database

    Hi.
     
    When I did the test above by appending "Hello World" to the text property I did get "hello World" in the database but nothing else.
     
    I have figured out something however.  If I switch from the Rich Text Editor mode to the Basic Text Box mode before submission it does record the HTML to the database.  But I would like to not ask the USER to have to do that cause I know more then a few will submit without switching first and have an empty string pas through.
     

    Here is my Page_Load  Sub:
     
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

                If Page.IsPostBack Then
                    'Page is a postback
                    updateDealerSettings() 'This is the Sub that fires the updates

                    LabelStatusMessage.Text = "Updated at " & DateTime.Now
                Else
                    'Page is not a postback
                    populateDataFields() 'This Sub reads anything that may be in the database OK.
                End If
    End Sub
     
     
     
  •  09-25-2008, 9:06 AM 44291 in reply to 44160

    Re: Saving the text value to a SQL Server database

    Woot!  I got it to work.
     
    All I did was move the Sub call.
     
    I took it out of the page_load event and put it in the button click event
     
            Protected Sub ButtonSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonSubmit.Click
                updateDealerSettings() 'Now it works =D
                LabelStatusMessage.Text = "Updated at " & DateTime.Now
            End Sub

     
    Thanks for all the guidance and time. :)
View as RSS news feed in XML