[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.webcontrols

I Builded a WebControl, but it reinitializes in every POST, How can I avoid this?

Andrés Giraldo

1/15/2003 6:19:00 PM

Hi!

I builded a webcontrol to simulate the VB6 DataControl, it works with a

dataset and worked fine, until I put the graphical interface... when a

user clicks on Next, Previous, First or Last button, it makes the

resposition as I expected, but it does a POST too, so the object it's

initialized again and every data on it it's lost...

I tried to put the control in the session object, and it works if I

call the reposition methods from the webform working with the object

stored in the session, but if I use the control button's it fails

again, even if I assign it the value of the object defined in the

session at the end of the postback event...

Any idea of how can I solve this?

Thanks!

-----------------------------------------------------
Here's my class code:

Imports System
Imports System.ComponentModel
Imports System.Data.OleDb
Imports System.Web.UI
Imports System.Web.UI.WebControls

Public Class MyRs
Inherits WebControls.WebControl
Implements INamingContainer

.. private attributes ...

Dim WithEvents btnPrevious As New Button()
Dim WithEvents btnFirst As New Button()
Dim WithEvents btnNext As New Button()
Dim WithEvents btnLast As New Button()
Dim WithEvents txtIndicator As New TextBox()

.. public properties ...

.. methods ...

Public Sub PreviousRecord()

End Sub

Private Sub btnPrevious_Clicked(ByVal sender As Object, ByVal e As

EventArgs)
PreviousRecord()
End Sub

.. other reposition methods ...

Protected Overrides Sub CreateChildControls()
With btnPrevious
.CausesValidation = False
.Font.Bold = True
.ID = "btnPrevious"
.TabIndex = 0
.Text = "<"
.ToolTip = "Go To The Previous Record"

AddHandler .Click, AddressOf btnPrevious_Clicked
End With

Controls.Add(btnPrevious)

.. creation of the other buttons ..

End Sub
End Class

-----------------------------------------------------
Here's my webform code:

Public Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents MyRS1 As MyRS
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents OleDbConnection1 As

System.Data.OleDb.OleDbConnection

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As

System.EventArgs) Handles MyBase.Load
If (Not IsPostBack) Then
Session("MyRS1") = MyRS1

With Session("MyRS1")
.Conexion = OleDbConnection1
.AbrirTabla("SELECT * FROM Test")
End With
End If

MyRS1 = Session("MyRS1") 'Even If I assign the value of the

object in session, it didn't works...
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As

System.EventArgs) Handles Button1.Click
With Session("MyRS1")
.FirstRecord() 'It Works, because I'm working with the

object defined in the session
End With
End Sub

End Class

*** Sent via Developersdex http://www.develop... ***
Don't just participate in USENET...get rewarded for it!