No data coming back

Discussion in 'ASP .Net Building Controls' started by Stanley, Oct 17, 2003.

  1. Stanley

    Stanley Guest

    Ok to see what was going on with my WYSIWYG control I decided to create a
    smaller control with just one simple textbox. The idea is to take in the
    text and write it out on the screen. Below is the server control and the
    ASPX page with its codebehind. I am still having a problem getting the
    postback from my control. Can anyone tell me what I am doing wrong here? As
    far as I can tell this should work.

    [webcontrol]

    Imports System.ComponentModel

    Imports System.Web.UI

    <DefaultProperty("Text"), ToolboxData("<{0}:WebCustomControl1
    runat=server></{0}:WebCustomControl1>")> Public Class WebCustomControl1

    Inherits System.Web.UI.WebControls.WebControl

    Implements IPostBackDataHandler

    Dim _text As String

    <Bindable(True), Category("Appearance"), DefaultValue("")> Property [Text]()
    As String

    Get

    Return _text

    End Get

    Set(ByVal Value As String)

    _text = Value

    End Set

    End Property

    Protected Overrides Sub Render(ByVal output As System.Web.UI.HtmlTextWriter)

    output.Write("<input type=text id=""" & Me.UniqueID & """ value=""" & [Text]
    & """>")

    End Sub

    Public Overridable Function LoadPostData(ByVal postDataKey As String, _

    ByVal postCollection As System.Collections.Specialized.NameValueCollection)
    _

    As Boolean _

    Implements IPostBackDataHandler.LoadPostData

    Dim oldText As String

    Dim newText As String

    oldText = [Text]

    newText = postCollection(postDataKey)

    If oldText = newText Then

    Return False

    Else

    [Text] = newText

    Return True

    End If

    End Function





    Public Overridable Sub RaisePostDataChangedEvent() _

    Implements IPostBackDataHandler.RaisePostDataChangedEvent

    OnTextChanged(EventArgs.Empty)

    End Sub



    Public Event TextChanged As EventHandler



    Public Overridable Sub OnTextChanged(ByVal e As EventArgs)

    RaiseEvent TextChanged(Me, e)

    End Sub

    End Class

    [/webcontrol]

    [ASPX]

    <%@ Register TagPrefix="cc1" Namespace="WebControlLibrary1"
    Assembly="WebControlLibrary1" %>

    <%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb"
    Inherits="WebControlTestPostBack.WebForm1"%>

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

    <HTML>

    <HEAD>

    <title>WebForm1</title>

    <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">

    <meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">

    <meta name="vs_defaultClientScript" content="JavaScript">

    <meta name="vs_targetSchema"
    content="http://schemas.microsoft.com/intellisense/ie5">

    </HEAD>

    <body MS_POSITIONING="GridLayout">

    <form id="Form1" method="post" runat="server">

    <cc1:WebCustomControl1 id="WebCustomControl11" style="Z-INDEX: 101; LEFT:
    480px; POSITION: absolute; TOP: 104px"

    runat="server"></cc1:WebCustomControl1>

    <asp:Button id="Button1" style="Z-INDEX: 102; LEFT: 536px; POSITION:
    absolute; TOP: 160px" runat="server"

    Text="Button"></asp:Button>

    </form>

    </body>

    </HTML>

    [/ASPX]

    [ASPX.vb]

    Public Class WebForm1

    Inherits System.Web.UI.Page

    #Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.

    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    Protected WithEvents WebCustomControl11 As
    WebControlLibrary1.WebCustomControl1

    Protected WithEvents Button1 As System.Web.UI.WebControls.Button

    'NOTE: The following placeholder declaration is required by the Web Form
    Designer.

    'Do not delete or move it.

    Private designerPlaceholderDeclaration As System.Object

    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 Sub Page_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load

    'Put user code to initialize the page here

    End Sub

    Private Sub WebCustomControl11_TextChanged(ByVal sender As System.Object,
    ByVal e As System.EventArgs) Handles WebCustomControl11.TextChanged

    Response.Write("text changed")

    Response.Write(WebCustomControl11.Text)

    End Sub

    End Class

    [/ASPX.vb]
     
    Stanley, Oct 17, 2003
    #1
    1. Advertising

  2. Stanley

    Stanley Guest

    Well I got the control to work sort of. If I populate the text field ahead
    of time and then try to change the text and then submit it I get the correct
    text up until here:

    Public Overridable Sub RaisePostDataChangedEvent() _

    Implements IPostBackDataHandler.RaisePostDataChangedEvent

    OnTextChanged(EventArgs.Empty) '<--text value is changed from new string to
    old string

    End Sub

    Why would firing my OnTextChanged method cause the text to go back to it's
    original value?

    "Stanley" <> wrote in message
    news:%...
    > Ok to see what was going on with my WYSIWYG control I decided to create a
    > smaller control with just one simple textbox. The idea is to take in the
    > text and write it out on the screen. Below is the server control and the
    > ASPX page with its codebehind. I am still having a problem getting the
    > postback from my control. Can anyone tell me what I am doing wrong here?

    As
    > far as I can tell this should work.
    >
    > [webcontrol]
    >
    > Imports System.ComponentModel
    >
    > Imports System.Web.UI
    >
    > <DefaultProperty("Text"), ToolboxData("<{0}:WebCustomControl1
    > runat=server></{0}:WebCustomControl1>")> Public Class WebCustomControl1
    >
    > Inherits System.Web.UI.WebControls.WebControl
    >
    > Implements IPostBackDataHandler
    >
    > Dim _text As String
    >
    > <Bindable(True), Category("Appearance"), DefaultValue("")> Property

    [Text]()
    > As String
    >
    > Get
    >
    > Return _text
    >
    > End Get
    >
    > Set(ByVal Value As String)
    >
    > _text = Value
    >
    > End Set
    >
    > End Property
    >
    > Protected Overrides Sub Render(ByVal output As

    System.Web.UI.HtmlTextWriter)
    >
    > output.Write("<input type=text id=""" & Me.UniqueID & """ value=""" &

    [Text]
    > & """>")
    >
    > End Sub
    >
    > Public Overridable Function LoadPostData(ByVal postDataKey As String, _
    >
    > ByVal postCollection As

    System.Collections.Specialized.NameValueCollection)
    > _
    >
    > As Boolean _
    >
    > Implements IPostBackDataHandler.LoadPostData
    >
    > Dim oldText As String
    >
    > Dim newText As String
    >
    > oldText = [Text]
    >
    > newText = postCollection(postDataKey)
    >
    > If oldText = newText Then
    >
    > Return False
    >
    > Else
    >
    > [Text] = newText
    >
    > Return True
    >
    > End If
    >
    > End Function
    >
    >
    >
    >
    >
    > Public Overridable Sub RaisePostDataChangedEvent() _
    >
    > Implements IPostBackDataHandler.RaisePostDataChangedEvent
    >
    > OnTextChanged(EventArgs.Empty)
    >
    > End Sub
    >
    >
    >
    > Public Event TextChanged As EventHandler
    >
    >
    >
    > Public Overridable Sub OnTextChanged(ByVal e As EventArgs)
    >
    > RaiseEvent TextChanged(Me, e)
    >
    > End Sub
    >
    > End Class
    >
    > [/webcontrol]
    >
    > [ASPX]
    >
    > <%@ Register TagPrefix="cc1" Namespace="WebControlLibrary1"
    > Assembly="WebControlLibrary1" %>
    >
    > <%@ Page Language="vb" AutoEventWireup="false"

    Codebehind="WebForm1.aspx.vb"
    > Inherits="WebControlTestPostBack.WebForm1"%>
    >
    > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    >
    > <HTML>
    >
    > <HEAD>
    >
    > <title>WebForm1</title>
    >
    > <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
    >
    > <meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
    >
    > <meta name="vs_defaultClientScript" content="JavaScript">
    >
    > <meta name="vs_targetSchema"
    > content="http://schemas.microsoft.com/intellisense/ie5">
    >
    > </HEAD>
    >
    > <body MS_POSITIONING="GridLayout">
    >
    > <form id="Form1" method="post" runat="server">
    >
    > <cc1:WebCustomControl1 id="WebCustomControl11" style="Z-INDEX: 101; LEFT:
    > 480px; POSITION: absolute; TOP: 104px"
    >
    > runat="server"></cc1:WebCustomControl1>
    >
    > <asp:Button id="Button1" style="Z-INDEX: 102; LEFT: 536px; POSITION:
    > absolute; TOP: 160px" runat="server"
    >
    > Text="Button"></asp:Button>
    >
    > </form>
    >
    > </body>
    >
    > </HTML>
    >
    > [/ASPX]
    >
    > [ASPX.vb]
    >
    > Public Class WebForm1
    >
    > Inherits System.Web.UI.Page
    >
    > #Region " Web Form Designer Generated Code "
    >
    > 'This call is required by the Web Form Designer.
    >
    > <System.Diagnostics.DebuggerStepThrough()> Private Sub

    InitializeComponent()
    >
    > End Sub
    >
    > Protected WithEvents WebCustomControl11 As
    > WebControlLibrary1.WebCustomControl1
    >
    > Protected WithEvents Button1 As System.Web.UI.WebControls.Button
    >
    > 'NOTE: The following placeholder declaration is required by the Web Form
    > Designer.
    >
    > 'Do not delete or move it.
    >
    > Private designerPlaceholderDeclaration As System.Object
    >
    > 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 Sub Page_Load(ByVal sender As System.Object, ByVal e As
    > System.EventArgs) Handles MyBase.Load
    >
    > 'Put user code to initialize the page here
    >
    > End Sub
    >
    > Private Sub WebCustomControl11_TextChanged(ByVal sender As System.Object,
    > ByVal e As System.EventArgs) Handles WebCustomControl11.TextChanged
    >
    > Response.Write("text changed")
    >
    > Response.Write(WebCustomControl11.Text)
    >
    > End Sub
    >
    > End Class
    >
    > [/ASPX.vb]
    >
    >
    >
    >
     
    Stanley, Oct 17, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jake Horn
    Replies:
    0
    Views:
    330
    Jake Horn
    Aug 26, 2004
  2. Microsoft News
    Replies:
    2
    Views:
    1,105
    Microsoft News
    Jan 27, 2005
  3. Sacha Korell
    Replies:
    6
    Views:
    3,080
    MasterGaurav
    Mar 9, 2005
  4. Colin Peters
    Replies:
    5
    Views:
    1,678
    Colin Peters
    Sep 4, 2005
  5. Steve Holden

    PyCon is Coming! PyCon is Coming!

    Steve Holden, Jan 5, 2006, in forum: Python
    Replies:
    0
    Views:
    316
    Steve Holden
    Jan 5, 2006
Loading...

Share This Page