In a vb.net 2010 web form application the user loads 'template letters' to a web
interface, that they can modify letters sent out to various customers to generate
various late pay notifications. The user basically selects the 'template letter' they want
to generate for a specific customer, and hits the 'save' button.
The web interface has the tabs for 'preview', 'html', and 'design' as the bottom of
editor. These tabs are not part of any custom code, they must be part of a web
interface that is inherited.
The values for the editor are stored in a sql server 2012 database in a field
called 'strTemplate' and the value is actually html.
The problem is once the html value for 'strTemplate' is loaded for the user to edit, extra blank lines are loaded between different parts of the 'templates. Basically extra <br></br> tags are generated.
When the user hits the save button, more <br></br> tags are generated between the various parts of the letter.
I do not want these extra blank lines to be generated.
I have gone into the html tab, removed the <br></br> tags and hit the save button. The extra tags are still generated. I have stepped through the code to find where the tags are generated and can not find it.
Thus can you tell me what I can do to not have the extra <br></br> tags generated?
The following is some of the code that is used when accessing the part of that gets to the web interface:
Imports System.Data
Imports System.Reflection
Imports System.Windows.Forms
Imports Telerik.Web.UI
Imports System.Web.Script.Services
Imports System.Web.Script.Serialization
Imports System.Web.Services
Partial Class edittemplates_default
Inherits System.Web.UI.Page
Protected _master As MasterPage
#Region "Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load"
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
_master = CType(Page.Master, MasterPage)
_master.PageTitle = "Edit Templates"
If Not Page.IsPostBack Then
If (edittemplates_default.SiteUserManager.SessionUser IsNot Nothing) Then
LoadTemplates()
LoadVariables()
Else
'pnlEditor.Enabled = False
'pnlEditor.Visible = False
End If
End If
Master.Page.Title = "Login"
End Sub
#End Region
#Region "Protected Sub LoadTemplates()"
Protected Sub LoadTemplates()
Dim et As EditTemplates = New EditTemplates()
Dim dt As DataTable = et.SelectTemplates()
For i = 0 To dt.Rows.Count() - 1
ddlTemplates.Items.Add(New ListItem(dt.Rows(i)(dt.Columns(1).ColumnName()), dt.Rows(i)(dt.Columns(0).ColumnName())))
Next
End Sub
#End Region
#Region "Protected Sub LoadVariables()"
Protected Sub LoadVariables()
Dim et As EditTemplates = New EditTemplates()
Dim dt As DataTable = et.SelectAtnLtrVariables()
For i = 0 To dt.Rows.Count() - 1
rlbVariables.Items.Add(New RadListBoxItem(dt.Rows(i)(dt.Columns(1).ColumnName()), dt.Rows(i)(dt.Columns(0).ColumnName())))
Next
End Sub
#End Region
#Region "Protected Sub btnSaveTemplate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSaveTemplate.Click"
Protected Sub btnSaveTemplate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSaveTemplate.Click
Dim et As EditTemplates = New EditTemplates()
If ddlTemplates.SelectedValue <> 0 Then
et.UpdateTemplate(ddlTemplates.SelectedValue, ddlLanguage.SelectedValue, rEditor.Content.ToString())
End If
End Sub
#End Region
-------------------
Partial Class edittemplates_default
Inherits System.Web.UI.Page
Protected _master As MasterPage
-----------
You are using a very old version of RadEditor, which does not support IE9 where the reported problem exists. To fix the problem it is recommended to upgrade to the latest Q2 2014 version, which will ensure that the editor will function as expected in all modern browsers.
You can also verify that the problem is fixed in the online demos of RadEditor: http://demos.telerik.com/aspnet-ajax/editor/examples/saveindatabase/defaultcs.aspx
Related
Im trying to create buttons on page load and have event controls to those. Im able to create the buttons but the event doesnt seem to be triggered when the button is clicked instead it throws an error stating multiple controls with id found.I think this has something to do with postback and unique ID creation for the buttons. can some one point me as to what to be added along with this?
Sub createbutton()
Dim but As New Button
but.Text = "save"
but.ID = "but"
AddHandler but.Click, AddressOf Button_Click
Me.form1.Controls.Add(but)
End Sub
The event control for this is as below.
Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
' Handle your Button clicks here
MsgBox("done")
End Sub
Im getting the error
Multiple controls with the same ID '1' were found
The subroutine createbutton works on page load as follows.
Public Class Default3
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load ' to gen page on load ;)
createbutton()
End Sub
Help is appreciated , Thanks :)
i think you are a guy who worked a lot with VB 6.0
Control array feature is available in VB 6.0
in VB.net everything is depend upon control ID.
if you don't have specific requirement like ID should be same then i suggest pls append prefix and incremental ID would resolve your issue.
Let me know if you have some specific requirements
Thanks
Asif
Corrected Code, Instead of ID it's name which allow uniqueness
Public Class Form1
Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
' Handle your Button clicks here
MsgBox("done")
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
createbutton()
End Sub
Sub createbutton()
Dim but As New Button
but.Text = "save"
but.Name = "but"
AddHandler but.Click, AddressOf Button_Click
Me.Controls.Add(but)
End Sub
End Class
What happens if one user tries to access an ASP.NET page twice before the first page is returned to the client? Have a look at the code below:
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Session("ID") = 1
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Response.Redirect("Default3.aspx")
End Sub End Class
Partial Class Default2
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Session("ID") = 2
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Response.Redirect("Default3.aspx")
End Sub
End Class
Imports System.Threading
Partial Class Default3
Inherits System.Web.UI.Page
Dim intTest As Integer = 0
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
For intTest = 0 To 10
Response.Write(Session("ID") & " " & intTest & "<br>")
Thread.Sleep(1000)
Next
End Sub
End Class
Accessing default3.axpx from the same client (PC) concurrently from default.aspx (by clicking button) and default2.aspx (by clicking button) causes the session variable to be the same on both requests (though I set the variable to 1 on the first request and 2 on the second). Is it possible to replicate this behaviour without threading? I believe I have this bug in an asp.net application that does not use threading.
Your question is not about multi-threading; it is about SessionState.
ASP.NET run time uses lock to avoid overriding same session variables although it can handles multiple requests.
It's why you are do not see miss-matching results.
Please also look at -
ASP.NET Application and Page Life Cycle
ASP.NET Application Life Cycle Overview
It's important to understand that session information is stored at the application level, and really has nothing directly to do with a page.
You could compare it to a global variable in a class. If all your methods are reading and writing to this variable, it will always contain the information from the last time it was updated. It doesn't matter how many times, or which methods, updated it.
To help see this in your code, create a new class with one property. Change your session variable to be an object of this class. Modify your session logic to refer to this object instead of a string, and update the property.
Finally, put a break point on the setter of your property.
This will let you see whenever your session variable is updated, and with what value. You can also view your stack trace to see what's setting it.
-note, this is all assuming you aren't introducing a farm into this and are accessing session from different machines--
I have a web application build using classic ASP and VB. How do I print a document from within the back end VB code?
Protected Sub btnPrint_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPrint.Click
End Sub
What i am trying to do is get user to click on button a letter is generated and sent to printer?
You could use the window.print javascript function which will open the print dialogon the client browser allowing him to choose the printer and print the page:
Protected Sub btnPrint_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPrint.Click
ClientScript.RegisterStartupScript([GetType](), "print", "window.print();", true)
End Sub
As a side note, what you have is not a classic ASP application with VB, you have a classic ASP.NET WebForms application using VB.NET as a code behind.
UPDATE:
As requested in the comments section here's how you could write a generic handler which will dynamically generate the HTML you would like to print:
Imports System.Web
Imports System.Web.Services
Public Class Print
Implements System.Web.IHttpHandler
Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
context.Response.ContentType = "text/html"
context.Response.Write("<html><body onload=""window.print();""><table><tr><td>value1</td><td>value1</td></tr></table></body></html>")
End Sub
ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
End Class
Now simply navigate to /Print.ashx.
you could look into some reports frameworks like CrystalReports (used to come with VS but you have to download it from SAP nowadays.
Here is a nice tutorial for the report-engine that comes packed into Visual Studio (I have to admit I don't have much experience with this but it looks fine to me): Creating an ASP.NET Report
i am using the WebBrowser control in asp.net page. here is the simple code:
Public Class _Default
Inherits System.Web.UI.Page
Private WithEvents browser As WebBrowser
Dim th As New Threading.Thread(AddressOf ThreadStart)
Sub ThreadStart()
browser = New WebBrowser
AddHandler browser.DocumentCompleted, AddressOf browser_DocumentCompleted
browser.Navigate("http://www.someurl.com/")
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
th.SetApartmentState(Threading.ApartmentState.STA)
th.Start()
th.Join()
End Sub
Private Sub browser_DocumentCompleted(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs)
If browser.Document IsNot Nothing Then
Dim textbox As HtmlElement = browser.Document.GetElementById("txt1")
textbox.InnerText = "some text"
Dim button As HtmlElement = browser.Document.GetElementById("btn1")
button.InvokeMember("click")
End If
End Sub
End Class
the problem is that the webbrowser's DocumentCompleted event is not being handled. It looks like the page request finishes before anything else could happen.
what's the solution to this problem?
I really recommend reading this article(He won a price for it..)
Using the WebBrowser Control in ASP.NET
http://www.codeproject.com/KB/aspnet/WebBrowser.aspx
His solution is to create 3 threads for it to work..
I'm not sure but I have some concerns about the way you wrote your code.
You are creating and initializing your thread as soon as your class instance is created. This is before the form has been loaded.
I can't say for sure this couldn't work but I would definitely recommend creating the thread in your Load event handler, just before you use it.
I wrote some similar code in C# to generate a website thumbnail. Although that code does not use the DocumentCompleted event, I played with that event when I wrote it and it seemed to work okay. You can compare my code to yours.
Also, I should mention I have one hosting account where the code doesn't work. It seems to simply die when I call Thread.Join. However, it doesn't appear that's the issue you're running into.
How can I call the Sub on the content page?
On the content page, there is let's say this:
Public Sub MySub()
End Sub
On the master page I have this:
Dim cph As ContentPlaceHolder = CType(Page.Form.FindControl("ContentPlaceHolder1"), ContentPlaceHolder)
Why do you need this? You can't be sure to have a particular contentpage. A Masterpage's purpose is re-usability and therefore many pages should use it. Why you need to access a special page?
What you could do is, add an event to the Masterpage, raise it when necessary and handle it in the ContentPage. For example...
in Master:
Partial Public Class ERPMaster
Inherits System.Web.UI.MasterPage
Public Event MasterLoaded(ByVal master As MasterPage)
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
RaiseEvent MasterLoaded(Me)
End Sub
In Content:
Private Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit
AddHandler DirectCast(Master, ERPMaster).MasterLoaded, AddressOf MasterLoaded
End Sub
Private Sub MasterLoaded(ByVal master As MasterPage)
MySub()
End Sub
Public Sub MySub()
End Sub
I assume that you are using ASP.NET?
Do you have a MasterType directive at the top of the content page file? If so, you can simply call functions on the master page using the following syntax:
Master.MySub()
The Master property of the content page is already typed to the page specified in the MasterType directive, so you can easily access any of the functions that it defines.
See MSDN for more information on interacting with master and client pages: http://msdn.microsoft.com/en-us/library/c8y19k6h(v=VS.100).aspx