No data coming back

S

Stanley

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]
 
S

Stanley

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 said:
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]
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,525
Members
44,997
Latest member
mileyka

Latest Threads

Top