Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Handling client side button click events to interact with other controls

Reply
Thread Tools

Handling client side button click events to interact with other controls

 
 
Matt Adamson
Guest
Posts: n/a
 
      02-25-2007
Guys,



Having issues with the code below which I would like the button click
handler on the client side to simply add the text box value to the list box.
When I press the add button the list box seems to get wider for a split
second but nothing is added. Any ideas?



ASPX



<%@ Control Language="C#" AutoEventWireup="true"
CodeFile="TransferTextToList.ascx.cs"
Inherits="Controls_TransferTextBoxToListBoxControl " %>

<asp:Label ID="textBoxLabel" runat="server" Text="Label"></asp:Label>

<asp:TextBox ID="sourceTextBox" runat="server"></asp:TextBox>

<asp:Button ID="addButton" runat="server" CausesValidation="False"
Text="Add" UseSubmitBehavior="False" />

<asp:ListBox ID="targetListBox" runat="server"></asp:ListBox>

<asp:Button ID="removeButton" runat="server" Text="Remove" />

and code behind

if
(!Page.ClientScript.IsClientScriptIncludeRegistere d("TransferTextToList"))

{

Page.ClientScript.RegisterClientScriptInclude( "TransferTextToList",

ResolveClientUrl("~/Controls/TransferTextToList.js"));

}

if ( ! IsPostBack)

{

addButton.OnClientClick = String.Format( "MoveItem('{0}', '{1}');",

sourceTextBox.ClientID,

targetListBox.ClientID);

}



TransferTextToList

function MoveItem(sourceTextBoxId, targetListBoxId)

{

var sourceElement = document.getElementById(sourceTextBoxId).value;

var targetElement = document.getElementById(targetListBoxId);

if (sourceElement != null)

{

// Create a new instance of ListItem

var newTargetOption = new Option();

newTargetOption.text = sourceElement;

newTargetOption.value = sourceElement;


// Append the item into the target list box

targetElement.options[targetElement.length] = newTargetOption;

}

}


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Button disabled and re-enabled in client side not firing server-side click event. =?Utf-8?B?QmluIFNvbmcsIE1DUA==?= ASP .Net 2 05-27-2008 09:57 AM
how client-side presentation code interact with server-side processing code? jrefactors@hotmail.com Javascript 1 12-08-2004 01:00 AM
how client-side presentation code interact with server-side filter/sort processing code? jrefactors@hotmail.com Javascript 0 12-07-2004 11:15 PM
client side vs server side events for controls Mong ASP .Net 5 05-07-2004 01:20 PM
asp:button w/ client side and server side click event Aymer ASP .Net Web Controls 1 09-19-2003 03:10 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57