473,396 Members | 2,002 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,396 software developers and data experts.

Never is postback ?

Hi,

I'm writing a little asp site, with just a single main default.aspx page and
a couple of web user's control.
I have the page in a way, that I have a left hand menu, and alternatively,
according to the selection, any of the .ascx components is loaded into a
tables's cell with the proper content.
This works great except for one thing : The menu on the left is a large list
of items retrieved from a database, in a datalist with an hypelink . Each
time any of these items is clicked, the query to retrieve this list is hit
again.
I have something like this :

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if (Page.IsPostBack == false)
{

DataList1.DataSource = get data reader; // SQL activity here
DataList1.DataBind();

if (Request.Params["goto"] != null)
{
string sGoto;
sGoto = Request.Params["goto"];
CenterPane.Controls.Add(Page.LoadControl("~/ResourcesList.ascx"));
CenterPane.Visible = true;
}
}

I thought that with the IsPostBack = false, I would avoid this code being
called in each click. I think that was wrong.

I'm looking advise on how to codify this in order to load the left hand menu
only once per user's session.
Thanks in advance,

Nov 18 '05 #1
1 992
Sounds to me like your hyperlinks you are generating in your datalist are
really hyperlinks. This would cause a fresh request to the page and
would reload your controls.

Solution:

Convert your hyperlinks to linkbuttons and handle the itemcommand event
of the datalist. The LinkButton performs a postback. Your list probably
had the ID value of whatever was chosen in the list passed on the
querystring. You can duplicate that functionality by using the
CommandArgument property of the LinkButton.

The code would look something like: (Sorry, I'm a VB guy, so you'll have
to do some rough translation)

private sub PopulateLinkbuttons(s, e) handles datalist1.itemdatabound
' This gets the linkbutton object and populates
' its command argument property.
' This runs for each row in your datalist
' only use item and altitem. header and foots and pagers
' don't have the linkbutton control in them.
' The link button is in your itemtemplate.
if e.item.itemtype=item or e.item.itemtype=alternatingitem then
dim l as linkbutton
l=e.item.findcontrol("TheLinkbutton")
l.commandname="LoadControl"
' You called this parameter "goto" below
l.commandargument=e.item.dataitem("goto")
end if
end sub

private sub LoadControl(s,e) handles datalist1.itemcommnd
if e.commandname="LoadControl" then
' Do what you do when you load the control
' Grab what you use "goto" from the commandargument
end if
end sub

You can see that you can have lots of link buttons each with their own
command name, and your itemcomand handler sub can do a case statement to
determine which button was clicked and which parameter was sent.

Best of luck!
"Craig Kenisston" <Cr************@hotmail.com> wrote in
news:#z**************@TK2MSFTNGP10.phx.gbl:
Hi,

I'm writing a little asp site, with just a single main default.aspx
page and a couple of web user's control.
I have the page in a way, that I have a left hand menu, and
alternatively, according to the selection, any of the .ascx components
is loaded into a tables's cell with the proper content.
This works great except for one thing : The menu on the left is a
large list of items retrieved from a database, in a datalist with an
hypelink . Each time any of these items is clicked, the query to
retrieve this list is hit again.
I have something like this :

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if (Page.IsPostBack == false)
{

DataList1.DataSource = get data reader; // SQL activity here
DataList1.DataBind();

if (Request.Params["goto"] != null)
{
string sGoto;
sGoto = Request.Params["goto"];
CenterPane.Controls.Add(Page.LoadControl("~/ResourcesList.ascx"));
CenterPane.Visible = true;
}
}

I thought that with the IsPostBack = false, I would avoid this code
being called in each click. I think that was wrong.

I'm looking advise on how to codify this in order to load the left
hand menu only once per user's session.
Thanks in advance,


Nov 18 '05 #2

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

Similar topics

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...
10
by: Mike Malter | last post by:
I have scoured the web looking for an example of how to do a javascript confirm box in .NET. Is there any way to do it? Thanks.
2
by: RAJ | last post by:
In our multi-tier application, we have several ASP.NET user controls which will update the same data source provided by middle tier logic. In this particular scenario we have one user control...
8
by: walesboy | last post by:
greetings - I have a btnSubmit button with a Handles btnSubmit.click which works great if all the user does is click that button. But, if the user ALSO changes a text box on the page (which...
4
by: Jim Hammond | last post by:
It would be udeful to be able to get the current on-screen values from a FormView that is databound to an ObjectDataSource by using a callback instead of a postback. For example: public void...
1
by: Timbo | last post by:
Hi all, This is my first message here so i'll try and include all the information that will help you help me out, if possible. Basically I am using C# in ASP.NET 2.0 and have a Repeater...
2
by: Wizzard | last post by:
I have a repeater with and imagebutton on a page useing VS2005 ASP.Net 2.0 <asp:Repeater ID="Repeater1" runat="server" > <ItemTemplate> <div> <asp:ImageButton ImageUrl="button.gif"...
11
by: antonyliu2002 | last post by:
I know that this has been asked and answered thousands of times. As a matter of fact, I know that I need to say If Not Page.IsPostBack Then 'Do something End If for things that needs to be...
7
by: Tony Girgenti | last post by:
Hello. I'm trying to undetrstand ASP.NET 2.0 and javascript. When i have a button and i click on it and i see the web broswer progress bar at the bottom do something, does that mean that there...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.