473,289 Members | 1,940 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,289 software developers and data experts.

Postback question

I have an asp page that contains a user control. This control is a panel
containing a number of link buttons that get displayed if certain conditions
in the db are met and these conditions can take quite a while to evaluate.
Consequently that page can take a while to open. These links are alert for
users indicating that they need to perform some actions. If they click any
of the links they will get redirected to the appropriate page.
Unfortunately, the action of clickin the link causes a postback which in
turn build the control which in turn checks the conditions which is a slow
process... All of this when all the user really wants to do is navigate to
a new page. Is there any way of avoiding all of this processing and just
drop straight into the event that caused the postback?
I have tried checking the IsPostback property on the Page_Load event and not
building the control if it is, but this does not work as there are no link
buttons to respond to!!

I have the same problem in other areas of the application where I have other
dynamically created controls (mainly datagrids). These grids generally have
a column containing an Edit button which, when clicked, causes a postback,
rebuilds the grid and populates the grid before it is able to detect which
rows Edit button was clicked and then redirect to another page. Again, if I
dont recreate the grid and populate at runtime, nothing happens in terms of
redirecting to required page.

Help appreciated

Terry Holland

May 17 '06 #1
6 2222
Terry, this is a tough one, for starters, the lifecycle can not be
shortcircuited so it is going to go to the page_load to the control_load and
then and only then to your event.
IsPostBack will not do it, because it will always be a postback relative to
your control. We had this issue on a project,doing a google search we
found the following:
(it uses a property to determine whether the control has been loaded for the
first time or not).HTH - Jose
On the user control code-behind add this property:

Private Property IsFirstLoad() As Boolean

Get

Dim o As Object = ViewState("MyUC-FirstLoad")

Return (o = Nothing)

End Get

Set(ByVal Value As Boolean)

ViewState("MyUC-FirstLoad") = True

End Set

End Property

Then add the code on your user control Page_Load:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

If IsFirstLoad = True Then

' Do Something

Else

' Whatever.

End If

IsFirstLoad = True

End Sub

"Terry Holland" <te**********@newsgroups.nospam> wrote in message
news:OI**************@TK2MSFTNGP04.phx.gbl...
I have an asp page that contains a user control. This control is a panel
containing a number of link buttons that get displayed if certain
conditions
in the db are met and these conditions can take quite a while to evaluate.
Consequently that page can take a while to open. These links are alert
for
users indicating that they need to perform some actions. If they click
any
of the links they will get redirected to the appropriate page.
Unfortunately, the action of clickin the link causes a postback which in
turn build the control which in turn checks the conditions which is a slow
process... All of this when all the user really wants to do is navigate
to
a new page. Is there any way of avoiding all of this processing and just
drop straight into the event that caused the postback?
I have tried checking the IsPostback property on the Page_Load event and
not
building the control if it is, but this does not work as there are no link
buttons to respond to!!

I have the same problem in other areas of the application where I have
other
dynamically created controls (mainly datagrids). These grids generally
have
a column containing an Edit button which, when clicked, causes a postback,
rebuilds the grid and populates the grid before it is able to detect which
rows Edit button was clicked and then redirect to another page. Again, if
I
dont recreate the grid and populate at runtime, nothing happens in terms
of
redirecting to required page.

Help appreciated

Terry Holland

May 17 '06 #2
Thanks for Jose's input.

Hi Terry,

As Jose has mentioned, ASP.NET page has fixed server-side processing model,
each request(no matter postback or not) will go through all the pipeline
and events. I think you're currently dynamically query the database and
constructing the controls in Page's Init or Load event, correct? IMO, if
you want to avoid the additional overhead when the user will click the
certain link button (dynamically created?), you can consider the following
options:

1. Make the redirection completely occur at client-side. That means do not
postback the page and user hyperlink instead of linkbutton.

2. Still postback, however, we no longer use the LinkButton's Click event
to do the redirection(or other server-side task) because click event of the
Linkbutton require that LinkButton be created again and added into Page's
control collection(this is not possible for your scenario since you do not
want to involve the addtional evaludation and control construction).
Instead, we can put a html input hidden field on the page. And for our
linkbuttons, we can register some client-side onclick script for them,
these script will set the sufficient information in the hidden field.
Then, when the page is postback (because of one of the linkbutton get
clicked), we can programmtically check that hidden field's value(directly
through Request.Forms Collection) and determine what operation to do or
where to redirect , all this is done before the evaluation and control
constructing code. How do you think?

Hope this helps.

Regards,

Steven Cheng
Microsoft Online Community Support
==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

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


May 18 '06 #3
I have overcome my linkbutton problem by modifying the stored procedure and
it now runs much faster.

I am however interested in using your suggestion for my dynamically created
datagrids. Could you prove some example code to get this to work please.

As previously mentioned, I dynamically add custom columns to my datagrid.
If the grid requires an Edit column then I call AddEditButton in my
InitialiseControl routine. This adds a clsImageButtonColumn column to my
grid with "Edit" as the command name.
If this button is clicked then DataGrid1_ItemCommand event is fired and
e.CommandName will be "Edit" and I fire my Datagrid's custom Edit event.

Im not sure where I would put the client side script that you are
suggesting.

Terry Holland

'=================================================
'Custom DataGrid Control - Add Edit Button To Grid
'=================================================
Private Sub AddEditButton()
Dim objImageInfo As clsImage_ROC.clsImageInfo =
m_objImage_ROC("List_Edit")
Dim objEC As New clsImageButtonColumn("Edit", objImageInfo)
'"../images/Edit.ICO")

With objEC
.HeaderStyle.Width = Unit.Pixel(25)
.HeaderStyle.HorizontalAlign = HorizontalAlign.Center
End With
DataGrid1.Columns.Add(objEC)
End Sub

'=================================================
'Custom DataGrid Control - Edit event
'=================================================
Private Sub DataGrid1_ItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
DataGrid1.ItemCommand
Dim intID As Integer = CType(e.Item.FindControl("lblID"),
Label).Text

Select Case e.CommandName
Case "Edit"
RaiseEvent Edit(intID)
Case "Delete"
RaiseEvent Delete(intID)
End Select
End Sub

'=================================================
'clsImageButtonColumn
'=================================================
Public Class clsImageButtonColumn
'Inherits System.Web.UI.UserControl

Inherits System.Web.UI.WebControls.DataGridColumn

Private m_strCommandName As String
'Private m_strImageURL As String
Private m_objImageInfo As clsImage_ROC.clsImageInfo

Private Sub New()

End Sub

Public Sub New(ByVal CommandName As String, ByVal objImageInfo As
clsImage_ROC.clsImageInfo)
m_strCommandName = CommandName
m_objImageInfo = objImageInfo

End Sub

Public Overrides Sub InitializeCell(ByVal cell As TableCell, ByVal
columnIndex As Integer, ByVal itemType As ListItemType)
MyBase.InitializeCell(cell, columnIndex, itemType)
If ((itemType <> ListItemType.Header) And (itemType <>
ListItemType.Footer)) Then

Dim ctl As WebControl = Nothing
Dim ibt As ImageButton = New
System.Web.UI.WebControls.ImageButton

ibt.ImageUrl = m_objImageInfo.Url ' m_strImageURL
ibt.AlternateText = m_objImageInfo.AltText
ibt.CommandName = m_strCommandName
ctl = ibt
cell.HorizontalAlign = HorizontalAlign.Center
cell.Controls.Add(ctl)
End If
End Sub
End Class
2. Still postback, however, we no longer use the LinkButton's Click event
to do the redirection(or other server-side task) because click event of the Linkbutton require that LinkButton be created again and added into Page's
control collection(this is not possible for your scenario since you do not
want to involve the addtional evaludation and control construction).
Instead, we can put a html input hidden field on the page. And for our
linkbuttons, we can register some client-side onclick script for them,
these script will set the sufficient information in the hidden field.
Then, when the page is postback (because of one of the linkbutton get
clicked), we can programmtically check that hidden field's value(directly
through Request.Forms Collection) and determine what operation to do or
where to redirect , all this is done before the evaluation and control
constructing code. How do you think?

Hope this helps.

Regards,

Steven Cheng
Microsoft Online Community Support
==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

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

May 18 '06 #4
Thanks for your response Terry,

Do you mean you want to register some client-script for your custom "edit"
column so that when the user clicks it, the column will use client-script
to do the redirection rather than let it postback? Or if I misunderstand,
would you provide some further description on this? Anyway, in your
scenario, if you want to add client script for your custom column, I
recommend you use GridView/DataGrid's ItemDataBound event which is fired
for each row's databinding, and you can get the the certain inner control
from each row and do some customization on them (such as registering client
script). e.g:

===========================
private void DataGrid1_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
Button btn = e.Item.FindControl("MyButtonid") as Button;
// do the customization on the button here....
}
}
=================================

Hope this helps.

Regards,

Steven Cheng
Microsoft Online Community Support
==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

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

May 22 '06 #5
Thank you

"Steven Cheng[MSFT]" wrote:
Thanks for your response Terry,

Do you mean you want to register some client-script for your custom "edit"
column so that when the user clicks it, the column will use client-script
to do the redirection rather than let it postback? Or if I misunderstand,
would you provide some further description on this? Anyway, in your
scenario, if you want to add client script for your custom column, I
recommend you use GridView/DataGrid's ItemDataBound event which is fired
for each row's databinding, and you can get the the certain inner control
from each row and do some customization on them (such as registering client
script). e.g:

===========================
private void DataGrid1_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
Button btn = e.Item.FindControl("MyButtonid") as Button;
// do the customization on the button here....
}
}
=================================

Hope this helps.

Regards,

Steven Cheng
Microsoft Online Community Support
==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

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


May 23 '06 #6
You're welcome :-)

Good luck!

Regards,

Steven Cheng
Microsoft Online Community Support
==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

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

May 24 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: JollyK | last post by:
Hi friends, This is my question.... From the Page Load event (or Page Init event), I would need to find which event had occurred that caused a PostBack, for example was it a event fired from...
5
by: Matthew Louden | last post by:
I created simple ASP.NET web application to test how AutoPostBack property in a web control works. I set AutoPostBack property to be true of a web control. When I run the application, here's the...
3
by: Jeremy | last post by:
I have an ASPX page with a bunch of System.Web.UI.WebControls.Button controls on it. By default, clicking on any of these causes a Postback. I'd like to have it so that for a couple of these...
9
by: Robert Galvin | last post by:
Is it possible to tell which control caused a postback?
3
by: Aleksandr Ayzin | last post by:
Hi, Basic question about PostBack: would it be accurate to say that PostBack is a direct result of triggered event that happened on the form(button clicked, text typed into textbox, so on). Is...
21
by: Martin Eyles | last post by:
I am trying to get javascript to cause a page to post back. I have tried calling _doPostBack from my script, but generates an error "object expected". I think this is because the page's script...
1
by: Marcus | last post by:
I have a problem maybe one of you could help me with. I've created a data entry screen with lots of dynamically-created client-side controls. I create HTML texboxes client-side by assigning a...
8
by: Matt MacDonald | last post by:
Hi All, I have a form that displays hierarchical categories in a treeview. Ok so far so good. What I was to do is have users be able to select a node in the treeview as part of filling out the...
2
by: brad | last post by:
Group, I'm using Visual Studio 2003 to create an ASP.NET 1.1 project which contains nested server user controls in order to create a tree-like hierarchy. The tree is a sort of question and...
4
by: Peter | last post by:
ASP.NET I have an application which use ASP.NET Autocomplete extender which works great. But I have a question how to update all the fields on the screen using Ajax. Users starts typing in a...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.