473,569 Members | 2,872 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2250
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.EventArg s) Handles MyBase.Load

If IsFirstLoad = True Then

' Do Something

Else

' Whatever.

End If

IsFirstLoad = True

End Sub

"Terry Holland" <te**********@n ewsgroups.nospa m> wrote in message
news:OI******** ******@TK2MSFTN GP04.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
InitialiseContr ol routine. This adds a clsImageButtonC olumn column to my
grid with "Edit" as the command name.
If this button is clicked then DataGrid1_ItemC ommand 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.cl sImageInfo =
m_objImage_ROC( "List_Edit" )
Dim objEC As New clsImageButtonC olumn("Edit", objImageInfo)
'"../images/Edit.ICO")

With objEC
.HeaderStyle.Wi dth = Unit.Pixel(25)
.HeaderStyle.Ho rizontalAlign = HorizontalAlign .Center
End With
DataGrid1.Colum ns.Add(objEC)
End Sub

'============== =============== =============== =====
'Custom DataGrid Control - Edit event
'============== =============== =============== =====
Private Sub DataGrid1_ItemC ommand(ByVal source As Object, ByVal e As
System.Web.UI.W ebControls.Data GridCommandEven tArgs) Handles
DataGrid1.ItemC ommand
Dim intID As Integer = CType(e.Item.Fi ndControl("lblI D"),
Label).Text

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

'============== =============== =============== =====
'clsImageButton Column
'============== =============== =============== =====
Public Class clsImageButtonC olumn
'Inherits System.Web.UI.U serControl

Inherits System.Web.UI.W ebControls.Data GridColumn

Private m_strCommandNam e As String
'Private m_strImageURL As String
Private m_objImageInfo As clsImage_ROC.cl sImageInfo

Private Sub New()

End Sub

Public Sub New(ByVal CommandName As String, ByVal objImageInfo As
clsImage_ROC.cl sImageInfo)
m_strCommandNam e = CommandName
m_objImageInfo = objImageInfo

End Sub

Public Overrides Sub InitializeCell( ByVal cell As TableCell, ByVal
columnIndex As Integer, ByVal itemType As ListItemType)
MyBase.Initiali zeCell(cell, columnIndex, itemType)
If ((itemType <> ListItemType.He ader) And (itemType <>
ListItemType.Fo oter)) Then

Dim ctl As WebControl = Nothing
Dim ibt As ImageButton = New
System.Web.UI.W ebControls.Imag eButton

ibt.ImageUrl = m_objImageInfo. Url ' m_strImageURL
ibt.AlternateTe xt = m_objImageInfo. AltText
ibt.CommandName = m_strCommandNam e
ctl = ibt
cell.Horizontal Align = HorizontalAlign .Center
cell.Controls.A dd(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_ItemD ataBound(object sender,
System.Web.UI.W ebControls.Data GridItemEventAr gs e)
{
if(e.Item.ItemT ype == ListItemType.It em || e.Item.ItemType ==
ListItemType.Al ternatingItem)
{
Button btn = e.Item.FindCont rol("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_ItemD ataBound(object sender,
System.Web.UI.W ebControls.Data GridItemEventAr gs e)
{
if(e.Item.ItemT ype == ListItemType.It em || e.Item.ItemType ==
ListItemType.Al ternatingItem)
{
Button btn = e.Item.FindCont rol("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
4052
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 the datagrid that caused a postback, or was it from a linkbutton, or was it from any other control on the page that have PostBack capabilities ? I am...
5
2036
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 sequences when I step through the program: 1. Page loaded to the browser 2. Page_Load method is called with non-postback event 3. The user has...
3
2498
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 buttons, no PostBack occurs - and rather some client-side script is executed (with no postback subsequently occuring). I have wired up the client-side...
9
375
by: Robert Galvin | last post by:
Is it possible to tell which control caused a postback?
3
1131
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 that the only way to trigger postback (esides AutoPostBack = True)or some other actions might initiate it? Thanks, --Alex
21
24418
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 doesn't contain the method _doPostBack, which needs to be added by asp.net. How can I make asp.net add this script? Thanks, ME --
1
3403
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 value to the td.innerHTML property. The UI is done, and I now want to post back the user's changes and update my business object in .NET. But when I...
8
12742
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 form. I only want to allow single selection, so using checkboxes is out of the question. It works as is, but it makes the form very cumbersome if...
2
2401
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 answer dialog. The user answers a question, and the next subquestion appears (using dynamic html display:none|block) depending on his answer.
4
5348
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 text field which causes the Autocomplete extender to display 10 like items, after the users selects an item (which is a key in the database) I want...
0
7619
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7930
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8138
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7983
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5228
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2118
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
950
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.