473,385 Members | 1,798 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,385 software developers and data experts.

Perform some functions on a listbox when i click in htmlbutton to avoid postback.

I want to perform some functions on a ListBox when I click an HTML button but I to avoid postback to minimise the server round trips....

Expand|Select|Wrap|Line Numbers
  1. protected void Assign_Button_Click(object sender, EventArgs e)
  2.         {
  3.             Button clickedButton = sender as Button;
  4.             if (clickedButton == null)
  5.             {
  6.                 return;
  7.             }
  8.  
  9.             if (clickedButton == Add_Button)
  10.             {
  11.                 if (Availableroles_ListBox.SelectedItem != null)
  12.                 {
  13.                     AssignedRoles_ListBox.Items.Add(Availableroles_ListBox.SelectedItem.ToString());
  14.                     Availableroles_ListBox.Items.Remove(Availableroles_ListBox.SelectedItem.ToString());
  15.                 }
  16.             }
  17.             else if (clickedButton == AddAll_Button)
  18.             {
  19.                 foreach (ListItem vv in Availableroles_ListBox.Items)
  20.                 {
  21.                     AssignedRoles_ListBox.Items.Add(vv.ToString());
  22.                 }
  23.                 Availableroles_ListBox.Items.Clear();
  24.             }
  25.             else if (clickedButton == Remove_Button)
  26.             {
  27.                 if (AssignedRoles_ListBox.SelectedItem != null)
  28.                 {
  29.                     Availableroles_ListBox.Items.Add(AssignedRoles_ListBox.SelectedItem.ToString());
  30.                     AssignedRoles_ListBox.Items.Remove(AssignedRoles_ListBox.SelectedItem.ToString());
  31.                 }
  32.             }
  33.             else if (clickedButton == RemoveAll_Button)
  34.             {
  35.                 foreach (ListItem vv in AssignedRoles_ListBox.Items)
  36.                 {
  37.                     Availableroles_ListBox.Items.Add(vv.ToString());
  38.                 }
  39.                 AssignedRoles_ListBox.Items.Clear();
  40.             }
  41.  
  42.         }
  43.  
Oct 8 '10 #1
2 1729
mzmishra
390 Expert 256MB
try to use javascript functions
Oct 8 '10 #2
Frinavale
9,735 Expert Mod 8TB
Looking over your code, it is going to be very tricky to do this using JavaScript. There is a way, but it isn't straightforward and requires some tricky stuff so that your page requests don't get caught up in ASP.NET Page Validation errors.

I recommend that you allow the postbacks to the server. You could consider using an UpdatePanel which makes use of Ajax (asynchronous requests/postbacks) so that the process is less noticeable to the end user.

-Frinny
Oct 8 '10 #3

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

Similar topics

9
by: msnews.microsoft.com | last post by:
Hello! I'm Jim by asp How can show "abc" in textbox when click one botton?
3
by: Mika | last post by:
Is it possible to perform functions on a recordset (rather than on the source database), e.g. COUNT, MAX etc The reason I would like to do this is because I have a hugely complex view which...
2
by: murdock | last post by:
Is there a way to perform functions upon databound data that is to be used in a GridView? For example, in the following code where I am using a GridView to display a resulting asp:SqlDataSource ...
2
by: VBLearner | last post by:
How to close the parent and all child forms together at once when click on parent window's close button X?
7
by: tapanreddy | last post by:
I am looking to perform an action when we close the window using the close tab at the top of the screen. I know how to do it using a close button but I was wondering if there is way to achieve the...
0
by: sat1582 | last post by:
I need avoid postback in a radio button control when press enter key, if you know how do this please tell me. Thanks for your response at sat1582@hotmail.com
0
by: Eraser | last post by:
Hi to all .NET guru guys... I have a problem in my delete button inside gridview. How to avoid postback on when i select cancel on confirmation message? But postback is okay on Ok confirmation....
1
by: m-sjoblom | last post by:
Hi On a form listbox Access version 2003 has a limited number or characters that can be stored in a listbox when the Row source Type is set to "Value List". Is there anybody that knows the...
2
by: hennas | last post by:
Telephone List Project Add item to Sequential text file load into memory and update listbox. When selecting item in list box is click must show in textbox. Two textbox Name and Telephone Number,...
1
by: su817200 | last post by:
Dear Friend, I would like to run multiple functions on Button Click eg... <input type="button" value="Update" name="B1" onclick="ReadFileToString() timedRefresh(1500)"></p> It is giving...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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...

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.