IsPostBack and usercontrols

D

David Lozzi

Hello,

I have an interesting issue, so bear with me as I try to explain. I have a
datalist posing as tabs for my application. And as each tab is clicked, a
placeholder is then populated with the associated control. For Example:

Details | Advanced | Configuration | Policies
<placeholder>

The jumping around works great. I can see each control when clicked. Here's
my problem. Each page has fields to be updated against my database. When a
user first clicks to edit the record, the page defaults to Details tab and
displays the corresponding data. Information can be updated successfully.
When clicking Details, or any tab for that matter, the user control loads
correctly but the data is not displayed because the call to load the data is
only when the page is not ispostback.

if not ispostback then
LoadData()
end if

So at first viewing, the page is not ispostback and it loads the data into
the fields. When a click on one of the tabs occurs, technically its a post
back because its all one page. Whats the best way to resolve this??

Thanks,
 
S

Steven Cheng[MSFT]

Hi David,

Welcome.
From your description, you're using DataList to build a navigate bar/menu
like control on a web page and when user clicking certain items on it, the
page will load a certain control(Usercontrol?) into a PlaceHolder on the
page. Since there exists Data Load code in the Control's internal code
which is done only in (!IsPostBack), you found that when you swtiching
between the different tabs, the Data will lost (not being loaded..) ,yes?
If anything I misunderstood, please feel free to let me know...

If the above is your current case, based on my experience, if your loading
data code is added in the Control's Load event handler's code, it can not
be controled by outside and is automatically called after the control is
added into the parent container and the parent's load event fires. So I
think you can consider exposing a public method on your Control which do
the samething as what you do current as below:

if not ispostback then
LoadData()
end if

Thus, we can call that public method to make your control loading data each
time the control has been added into the parent container (when user click
a new menu item in DataList....)

How do you think of this?

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


--------------------
| From: "David Lozzi" <[email protected]>
| Subject: IsPostBack and usercontrols
| Date: Thu, 1 Dec 2005 16:47:21 -0500
| Lines: 35
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| X-RFC2646: Format=Flowed; Original
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: c-24-63-42-200.hsd1.ma.comcast.net 24.63.42.200
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:362176
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Hello,
|
| I have an interesting issue, so bear with me as I try to explain. I have
a
| datalist posing as tabs for my application. And as each tab is clicked, a
| placeholder is then populated with the associated control. For Example:
|
| Details | Advanced | Configuration | Policies
| <placeholder>
|
| The jumping around works great. I can see each control when clicked.
Here's
| my problem. Each page has fields to be updated against my database. When
a
| user first clicks to edit the record, the page defaults to Details tab
and
| displays the corresponding data. Information can be updated successfully.
| When clicking Details, or any tab for that matter, the user control loads
| correctly but the data is not displayed because the call to load the data
is
| only when the page is not ispostback.
|
| if not ispostback then
| LoadData()
| end if
|
| So at first viewing, the page is not ispostback and it loads the data
into
| the fields. When a click on one of the tabs occurs, technically its a
post
| back because its all one page. Whats the best way to resolve this??
|
| Thanks,
|
| --
| David Lozzi
| Web Applications Developer
| dlozzi@(remove-this)delphi-ts.com
|
|
|
|
|
 
D

David Lozzi

Yeah I was working on that, but I just got it to work. Thanks for the help!!

--
David Lozzi
Web Applications Developer
dlozzi@(remove-this)delphi-ts.com
 
D

David Lozzi

OK, I lied. It was working but not correctly The LoadData was being run on
everytime the page loaded. I got a little excited. I am still having the
same issue. Here is my partial scripts:

***** tabs page *****
Public DefaultControl As String
Public Tabs As ArrayList
Private ContentControl As Control
Public ActiveClass As String
Public InactiveClass As String
Private EID As Integer

Private Sub dlSolMenu_ItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataListCommandEventArgs) Handles
dlSolMenu.ItemCommand
dlSolMenu.SelectedIndex = e.Item.ItemIndex

LoadTab(e.CommandArgument)

CType(ContentControl, iTab).Initialize()
End Sub

Sub LoadTab(Optional ByVal controlName As String = "")
If controlName = "" Then
controlName = DefaultControl
dlSolMenu.SelectedIndex = 0
End If

ContentControl = Page.LoadControl(("~/admin/" & controlName))
CType(ContentControl, ITab).EID = EID
plhContent.Controls.Clear()
plhContent.Controls.Add(ContentControl)
ContentControl.ID = "ctlContent"
End Sub 'LoadTab
*****

***** details user class top 60 lines *****
Public Class details
Inherits System.Web.UI.UserControl
Implements ITab

#Region " Web Form Designer Generated Code "

Public _eid As Integer

Public Property EID() As Integer Implements ITab.EID
Get
Return _eid
End Get
Set(ByVal Value As Integer)
_eid = Value
End Set
End Property

Public Sub Initialize() Implements ITab.Initialize
LoadData()
lblError.Text = "Initialized"
End Sub 'Init
*****

***** iTab definition *****
Namespace UserInterfaceLayer
Public Interface ITab

Property EID() As Integer

Sub Initialize()

End Interface 'ITab
End Namespace
*****

If I put the initialize command right after the line where the EID is
assigned in LoadTab(), the data loads everytime. This is bad because I
cannot update the data. The dlSolMenu_ItemCommand is suppose to call the
Initialize sub, but it doesn't.

Thanks!!

--
David Lozzi
Web Applications Developer
dlozzi@(remove-this)delphi-ts.com
 
D

David Lozzi

GOT IT! Yeah me! Updated my script as follows:

Sub LoadTab(Optional ByVal NewControlName As String = "")
Dim controlName As String

If NewControlName = "" Then
controlName = DefaultControl
Else
controlName = NewControlName
End If
ContentControl = Page.LoadControl(("~/admin/" & controlName))
CType(ContentControl, ITab).EID = EID
plhContent.Controls.Clear()
plhContent.Controls.Add(ContentControl)
ContentControl.ID = "ctlContent"
End Sub 'LoadTab

And put the LoadTab() in Page_load. and it works great. I can also update
info on the controls. Thanks for your help!!

--
David Lozzi
Web Applications Developer
dlozzi@(remove-this)delphi-ts.com
 
S

Steven Cheng[MSFT]

Cool! Glad that you've got it working.

Have a nice day!

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| From: "David Lozzi" <[email protected]>
| References: <[email protected]>
<#[email protected]>
<[email protected]>
| Subject: Re: IsPostBack and usercontrols
| Date: Fri, 2 Dec 2005 15:58:08 -0500
| Lines: 231
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| X-RFC2646: Format=Flowed; Response
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| Message-ID: <#[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: c-24-63-42-200.hsd1.ma.comcast.net 24.63.42.200
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:362418
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| GOT IT! Yeah me! Updated my script as follows:
|
| Sub LoadTab(Optional ByVal NewControlName As String = "")
| Dim controlName As String
|
| If NewControlName = "" Then
| controlName = DefaultControl
| Else
| controlName = NewControlName
| End If
| ContentControl = Page.LoadControl(("~/admin/" & controlName))
| CType(ContentControl, ITab).EID = EID
| plhContent.Controls.Clear()
| plhContent.Controls.Add(ContentControl)
| ContentControl.ID = "ctlContent"
| End Sub 'LoadTab
|
| And put the LoadTab() in Page_load. and it works great. I can also update
| info on the controls. Thanks for your help!!
|
| --
| David Lozzi
| Web Applications Developer
| dlozzi@(remove-this)delphi-ts.com
|
|
|
| | > OK, I lied. It was working but not correctly The LoadData was being run
on
| > everytime the page loaded. I got a little excited. I am still having
the
| > same issue. Here is my partial scripts:
| >
| > ***** tabs page *****
| > Public DefaultControl As String
| > Public Tabs As ArrayList
| > Private ContentControl As Control
| > Public ActiveClass As String
| > Public InactiveClass As String
| > Private EID As Integer
| >
| > Private Sub dlSolMenu_ItemCommand(ByVal source As Object, ByVal e As
| > System.Web.UI.WebControls.DataListCommandEventArgs) Handles
| > dlSolMenu.ItemCommand
| > dlSolMenu.SelectedIndex = e.Item.ItemIndex
| >
| > LoadTab(e.CommandArgument)
| >
| > CType(ContentControl, iTab).Initialize()
| > End Sub
| >
| > Sub LoadTab(Optional ByVal controlName As String = "")
| > If controlName = "" Then
| > controlName = DefaultControl
| > dlSolMenu.SelectedIndex = 0
| > End If
| >
| > ContentControl = Page.LoadControl(("~/admin/" & controlName))
| > CType(ContentControl, ITab).EID = EID
| > plhContent.Controls.Clear()
| > plhContent.Controls.Add(ContentControl)
| > ContentControl.ID = "ctlContent"
| > End Sub 'LoadTab
| > *****
| >
| > ***** details user class top 60 lines *****
| > Public Class details
| > Inherits System.Web.UI.UserControl
| > Implements ITab
| >
| > #Region " Web Form Designer Generated Code "
| >
| > Public _eid As Integer
| >
| > Public Property EID() As Integer Implements ITab.EID
| > Get
| > Return _eid
| > End Get
| > Set(ByVal Value As Integer)
| > _eid = Value
| > End Set
| > End Property
| >
| > Public Sub Initialize() Implements ITab.Initialize
| > LoadData()
| > lblError.Text = "Initialized"
| > End Sub 'Init
| > *****
| >
| > ***** iTab definition *****
| > Namespace UserInterfaceLayer
| > Public Interface ITab
| >
| > Property EID() As Integer
| >
| > Sub Initialize()
| >
| > End Interface 'ITab
| > End Namespace
| > *****
| >
| > If I put the initialize command right after the line where the EID is
| > assigned in LoadTab(), the data loads everytime. This is bad because I
| > cannot update the data. The dlSolMenu_ItemCommand is suppose to call
the
| > Initialize sub, but it doesn't.
| >
| > Thanks!!
| >
| > --
| > David Lozzi
| > Web Applications Developer
| > dlozzi@(remove-this)delphi-ts.com
| >
| >
| >
| > | >> Hi David,
| >>
| >> Welcome.
| >> From your description, you're using DataList to build a navigate
bar/menu
| >> like control on a web page and when user clicking certain items on it,
| >> the
| >> page will load a certain control(Usercontrol?) into a PlaceHolder on
the
| >> page. Since there exists Data Load code in the Control's internal code
| >> which is done only in (!IsPostBack), you found that when you swtiching
| >> between the different tabs, the Data will lost (not being loaded..)
,yes?
| >> If anything I misunderstood, please feel free to let me know...
| >>
| >> If the above is your current case, based on my experience, if your
| >> loading
| >> data code is added in the Control's Load event handler's code, it can
not
| >> be controled by outside and is automatically called after the control
is
| >> added into the parent container and the parent's load event fires. So
I
| >> think you can consider exposing a public method on your Control which
do
| >> the samething as what you do current as below:
| >>
| >> if not ispostback then
| >> LoadData()
| >> end if
| >>
| >> Thus, we can call that public method to make your control loading data
| >> each
| >> time the control has been added into the parent container (when user
| >> click
| >> a new menu item in DataList....)
| >>
| >> How do you think of this?
| >>
| >> Regards,
| >>
| >> Steven Cheng
| >> Microsoft Online Support
| >>
| >> Get Secure! www.microsoft.com/security
| >> (This posting is provided "AS IS", with no warranties, and confers no
| >> rights.)
| >>
| >>
| >> --------------------
| >> | From: "David Lozzi" <[email protected]>
| >> | Subject: IsPostBack and usercontrols
| >> | Date: Thu, 1 Dec 2005 16:47:21 -0500
| >> | Lines: 35
| >> | X-Priority: 3
| >> | X-MSMail-Priority: Normal
| >> | X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| >> | X-RFC2646: Format=Flowed; Original
| >> | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| >> | Message-ID: <[email protected]>
| >> | Newsgroups: microsoft.public.dotnet.framework.aspnet
| >> | NNTP-Posting-Host: c-24-63-42-200.hsd1.ma.comcast.net 24.63.42.200
| >> | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
| >> | Xref: TK2MSFTNGXA02.phx.gbl
| >> microsoft.public.dotnet.framework.aspnet:362176
| >> | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| >> |
| >> | Hello,
| >> |
| >> | I have an interesting issue, so bear with me as I try to explain. I
| >> have
| >> a
| >> | datalist posing as tabs for my application. And as each tab is
clicked,
| >> a
| >> | placeholder is then populated with the associated control. For
Example:
| >> |
| >> | Details | Advanced | Configuration | Policies
| >> | <placeholder>
| >> |
| >> | The jumping around works great. I can see each control when clicked.
| >> Here's
| >> | my problem. Each page has fields to be updated against my database.
| >> When
| >> a
| >> | user first clicks to edit the record, the page defaults to Details
tab
| >> and
| >> | displays the corresponding data. Information can be updated
| >> successfully.
| >> | When clicking Details, or any tab for that matter, the user control
| >> loads
| >> | correctly but the data is not displayed because the call to load the
| >> data
| >> is
| >> | only when the page is not ispostback.
| >> |
| >> | if not ispostback then
| >> | LoadData()
| >> | end if
| >> |
| >> | So at first viewing, the page is not ispostback and it loads the data
| >> into
| >> | the fields. When a click on one of the tabs occurs, technically its a
| >> post
| >> | back because its all one page. Whats the best way to resolve this??
| >> |
| >> | Thanks,
| >> |
| >> | --
| >> | David Lozzi
| >> | Web Applications Developer
| >> | dlozzi@(remove-this)delphi-ts.com
| >> |
| >> |
| >> |
| >> |
| >> |
| >>
| >
| >
|
|
|
 

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,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top