473,402 Members | 2,050 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,402 developers and data experts.

When to use AutopostBack

AutopostBack is a property typically used in Dropdownlist,Radiobuttonlist, ListBox controls.
You will use this controls to dispaly set of items,
when you click on item in the list,selectedindexchanged
event will be fired.anyway by default nothing happens with
this event.
if you want an action has to be occured.you should make autopostback="True".so whenever an event should fire and
need to data to be postedback you will use this..
here is an example of autopostback..

Source Code:

Expand|Select|Wrap|Line Numbers
  1. <body>
  2.     <form id="form1" runat="server">
  3.     <div>
  4.     <asp:ListBox ID="lb1" Rows="4" runat="server" AutoPostBack="true" >
  5.     <asp:ListItem>India</asp:ListItem>
  6.     <asp:ListItem>Southafrica</asp:ListItem>
  7.     <asp:ListItem>Australia</asp:ListItem>
  8.     <asp:ListItem>England</asp:ListItem>
  9.  
  10.  
  11.     </asp:ListBox>
  12.     <br />
  13.     <br />
  14.     <asp:Label ID="lab1" runat="server">
  15.     </asp:Label>
  16.     </div>
  17.     </form>
  18. </body> 
  19.  
Code behind:

Expand|Select|Wrap|Line Numbers
  1. protected void Page_Load(object sender, EventArgs e)
  2.         {
  3.  
  4.         }
  5.  
  6.         protected void lb1_SelectedIndexChanged(object sender, EventArgs e)
  7.         {
  8.             if (lb1.SelectedItem != null)
  9.             {
  10.                 lab1.Text = "you selected" + lb1.SelectedItem.Value;
  11.             }
  12.             else
  13.             {
  14.                 lab1.Text = "";
  15.             }
  16.  
  17.         }
  18.  
Note: you can also write that code in Page_load event also...
May 9 '12 #1
1 47941
Good Post. Simple and Useful.
Jun 18 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Susan van Houen | last post by:
Hi All, How do I intercept an autopostback on the client side and prevent it from executing the submit? In classic ASP I used to intercept the on_submit and just return false;
3
by: Lloyd Sheen | last post by:
I have a page that works fine. I am trying to optimize the page by overriding some of the Information that is being saved in the hidden VIEWSTATE. If I make the properties of the dropdown False...
8
by: Matthew Louden | last post by:
why need to set autopostback property to be true?? I know autopostback event means to send the form to the server automatically. I tried checkbox, checkbox list, radio button, and radio button...
1
by: John Oakes | last post by:
I have a TextBox with AutoPostBack = True. Often a user needs to click directly from this control to a RadioButtonList. Because the TextBox immediately posts back, the RadioButtonList selection...
2
by: Tom Edelbrok | last post by:
Question: Why does a button event (ie: Button1_Click) get executed on the first click for a textbox control which has 'autopostback=false', but doesn't get executed until a second click when...
3
by: Brad | last post by:
The first text on my form is a numeric field. I have a javascript that runs on this field for onkeyup (validate the key strokes and modifies fields on the screen) but when I do this and have the...
2
by: rn5a | last post by:
Assume that a user control has a TextBox (Page1.ascx) <asp:TextBox ID="txtName" runat="server"/> I am encapsulating the above user control in a ASPX page named Page1.aspx i.e. the ASPX page...
6
by: Peter | last post by:
ASP.NET 2.0 Visual Studio 2008 I have the following code and when the textbox displays and I press Enter while in the text box I get AutoPostBack, how do I stop AutoPostBack? TextBox txt =...
0
by: asmx126453 | last post by:
Hey mensen I am having some big troubles here i tryd solving it myself with internet for 2 days but i kind fix it. Its about this i have a DotNet project that alrydi is online and working for...
1
by: Billie Hartline | last post by:
I am an untrained volunteer seekeing help. I have several input pages where I autopostback is marked "True", when I enter the data or select the entry. The page flashes a losses its normal tab...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
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.