Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Any one please convert this code in C# Code

VB
Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.ComponentModel
Imports System.Text


Namespace LNTSystems.CommonControls
    Partial Class MsgBox
        Inherits System.Web.UI.UserControl

#Region " Web Form Designer Generated Code "
         'This call is required by the Web Form Designer.
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

        End Sub


        Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
            'CODEGEN: This method call is required by the Web Form Designer
            'Do not modify it using the code editor.
            InitializeComponent()
        End Sub

#End Region
        Private content As String
        Public Sub alert(ByVal msg As String)
            Dim sMsg As String = msg.Replace("" & Microsoft.VisualBasic.Chr(10) & "", "\n")
            sMsg = msg.Replace("""", "'")
            Dim sb As StringBuilder = New StringBuilder
            sb.Append("<script language='javascript'>")
            sb.Append("alert( """ + sMsg + """ );")
            sb.Append("</script>")
            content = sb.ToString
        End Sub
        Public Sub alert(ByVal msg As String, ByVal Redirect As String)
            Dim sMsg As String = msg.Replace("" & Microsoft.VisualBasic.Chr(10) & "", "\n")
            sMsg = msg.Replace("""", "'")
            Dim sb As StringBuilder = New StringBuilder
            sb.Append("<script language='javascript'>")
            sb.Append("alert( """ + sMsg + """ );")
            sb.Append("window.navigate( """ + Redirect + """ );")
            sb.Append("</script>")
            content = sb.ToString
        End Sub

        Public Sub confirm(ByVal msg As String, ByVal hiddenfield_name As String)
            Dim sMsg As String = msg.Replace("" & Microsoft.VisualBasic.Chr(10) & "", "\n")
            sMsg = msg.Replace("""", "'")
            Dim sb As StringBuilder = New StringBuilder
            sb.Append("<INPUT type=hidden value='0' name='" + hiddenfield_name + "'>")
            sb.Append("<script language='javascript'>")
            sb.Append(" if(confirm( """ + sMsg + """ ))")
            sb.Append(" { ")
            sb.Append("document.forms[0]." + hiddenfield_name + ".value='1';" + "document.forms[0].submit(); }")
            sb.Append(" else { ")
            sb.Append("document.forms[0]." + hiddenfield_name + ".value='0'; }")
            sb.Append("</script>")
            content = sb.ToString
        End Sub

        Protected Overloads Overrides Sub Render(ByVal output As HtmlTextWriter)
            output.Write(Me.content)
        End Sub

    End Class

End Namespace


i'm following this link . but in above code hwenever "Chr" is there in that it show some error doesn't contain a definition for Chr.
http://www.developerfusion.com/tools/convert/vb-to-csharp/[^]
Posted

 
Share this answer
 
Here is a tool: http://www.tangiblesoftwaresolutions.com/[^]Since conversion tool sometimes have wrong code, so I am not sure it must be all right after converting, you can try. Good luck!
 
Share this answer
 
Code translators aren't 100% in converting from VB.NET to C#, you will need to manually change some code like you have found the Microsoft.VisualBasic.Chr(10) as one of them

these links show you how to do the same in C#

What is the C# equivalent of the chr() function?[^]

C# equivilent for Asc and Chr[^]

but here is a simple example conversion

C#
Dim sMsg As String = msg.Replace("" & Microsoft.VisualBasic.Chr(10) & "", "\n")


To

C#
Char newLine = (char)10;
string sMsg = msg.Replace(newLine, @"\n");
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900