borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (how to attach regular expression with textbox in asp.net?)Next Topic (Difference between C# and VB.Net ?) New Topic New Poll Post Reply
AndreaVB Forum : ASP.Net : encounter script error after developing custom webcontrol?
Poster Message
tri_inn
Level: Regular User
Registered: 26-08-2002
Posts: 395

icon encounter script error after developing custom webcontrol?

i have developed a web custom control which will accept only number,decimal number and negative value also.
after putting my control onto the web form and when i am running my appliation it is giving script error
because my control generates javascript where error lies, so please tell me where the actual error occured.
i am giving full source code of my control and you just tell me where and why error lies and occured.

my source code follows :-

Imports System.ComponentModel
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System


<DefaultProperty(""), ToolboxData("<{0}:NumBox runat=server></{0}:NumBox>")> Public Class NumBox
    Inherits System.Web.UI.WebControls.TextBox

    Private m_Deciplace As Integer = 0
    Private m_Negative As Boolean = False

    <Bindable(True), Category("Appearance"), DefaultValue("")> Property Decimalplace() As Integer
        Get
            Return m_Deciplace
        End Get

        Set(ByVal Value As Integer)
            m_Deciplace = Value
        End Set
    End Property

    <Bindable(True), Category("Appearance"), DefaultValue("")> Property AllowNegative() As Boolean
        Get
            Return m_Negative
        End Get

        Set(ByVal Value As Boolean)
            m_Negative = Value
        End Set
    End Property

    Private Sub NumBox_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.PreRender
        Dim scriptString As String = "<script language=JavaScript>"
        scriptString &= "function DoCheck_" & Me.ClientID & "(event)" & vbCrLf
        scriptString &= "{" & vbCrLf
        scriptString &= "var negative" & vbCrLf
        scriptString &= "var Decimal = 46" & vbCrLf
        scriptString &= "var DeciPlaces =" & Decimalplace & vbCrLf
        scriptString &= "var AllowNegative =" & AllowNegative & vbCrLf
        scriptString &= "var myString = new String(event.srcElement.value);" & vbCrLf
        scriptString &= "var pntPos = myString.indexOf(String.fromCharCode(Decimal));" & vbCrLf
        scriptString &= "var keyChar = window.event.keyCode;" & vbCrLf

        scriptString &= "If (AllowNegative==true) Then" & vbCrLf
        scriptString &= "{"
        scriptString &= "negative=myString.indexOf('-');" & vbCrLf
        scriptString &= "If (negative = -1) Then" & vbCrLf
        scriptString &= "{" & vbCrLf
        scriptString &= "If (myString.length <= 0) Then" & vbCrLf
        scriptString &= "return true;" & vbCrLf
        scriptString &= "}" & vbCrLf
        scriptString &= "Else" & vbCrLf
        scriptString &= "{" & vbCrLf
        scriptString &= "return false;" & vbCrLf
        scriptString &= "}" & vbCrLf
        scriptString &= "}" & vbCrLf

        scriptString &= "if (keyChar == Decimal)" & vbCrLf
        scriptString &= "{" & vbCrLf
        scriptString &= "if (pntPos != -1)" & vbCrLf
        scriptString &= "{" & vbCrLf
        scriptString &= "return false;" & vbCrLf
        scriptString &= "}" & vbCrLf
        scriptString &= "return true;" & vbCrLf
        scriptString &= "}" & vbCrLf

        scriptString &= "if ((keyChar < 48) || (keyChar > 57))" & vbCrLf
        scriptString &= "{" & vbCrLf
        scriptString &= "return false;" & vbCrLf
        scriptString &= "}" & vbCrLf
        scriptString &= "Else" & vbCrLf
        scriptString &= "{" & vbCrLf
        scriptString &= "if (pntPos != -1)" & vbCrLf
        scriptString &= "{" & vbCrLf
        scriptString &= "If ((myString.length - (pntPos + 1)) >= DeciPlaces)" & vbCrLf
        scriptString &= "return false;" & vbCrLf
        scriptString &= "}" & vbCrLf
        scriptString &= "Else" & vbCrLf
        scriptString &= "{" & vbCrLf
        scriptString &= "return true;" & vbCrLf
        scriptString &= "}" & vbCrLf
        scriptString &= "}" & vbCrLf
        scriptString &= "}" & vbCrLf
        scriptString &= "</script>"

        If Not Page.IsClientScriptBlockRegistered("clientScript") Then
            Page.RegisterClientScriptBlock("clientScript", scriptString)
        End If
        Me.Attributes.Add("onKeypress", "return DoCheck_" & Me.ClientID & "(event)")
    End Sub
End Class

11-08-2004 at 12:08 PM
View Profile Send Email to User Show All Posts | Quote Reply
zimcoder
Level: VB Lord


Registered: 27-10-2003
Posts: 225
icon Re: encounter script error after developing custom webcontrol?

What is the actual error generated?

____________________________
BrainBench ADO.NET and ASP.NET Certified Developer

31-08-2004 at 07:39 AM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : ASP.Net : encounter script error after developing custom webcontrol?
Previous Topic (how to attach regular expression with textbox in asp.net?)Next Topic (Difference between C# and VB.Net ?) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder