To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
VBForums  

VB Wire News
Part 10 of the Visual Basic .NET 2010 Express Tutorial Complete!
How to Use the Visual Studio Code Analysis Tool FxCop
Article :: Interview with Andrei Alexandrescu (Part 3 of 3)
Introducing Visual Studio LightSwitch
Visual Studio LightSwitch Beta 1 is Available



Go Back   VBForums > .NET > ASP.NET

Reply Post New Thread
 
Thread Tools Display Modes
Old Apr 5th, 2005, 01:06 AM   #1
usamaalam
Frenzied Member
 
usamaalam's Avatar
 
Join Date: Nov 02
Location: Karachi
Posts: 1,267
usamaalam is on a distinguished road (10+)
How to use server control in JavaScript

Hello everybody,

I need to use my server controls in javascript for client-side validation etc.

I have a listbox control.

<asp:listbox id=groupsListBox runat="server" Width="256px" OnSelectedIndexChanged="javascript:SetTextBox();"></asp:listbox>

As user selects a value, I need to display this value in the TextBox just below the listbox. I wrote the code in SetTextBox() but this function does not execute.

Thanks.
__________________
The secret of creativity is knowing how to hide your sources...
usamaalam is offline   Reply With Quote
Old Apr 5th, 2005, 02:25 AM   #2
Brandoe85
Member
 
Join Date: Mar 05
Posts: 56
Brandoe85 is on a distinguished road (10+)
Re: How to use server control in JavaScript

Well i've never used OnSelectedIndexChanged before, but what happends if you use the onChange event? This is the html of an example I made that works:

VB Code:
  1. <%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="WebApplication3.WebForm1"%>
  2. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  3. <HTML>
  4.     <HEAD>
  5.         <title>WebForm1</title>
  6.         <script type="text/javascript">
  7.         function change(e)
  8.         {
  9.             var yak = document.getElementById('TextBox3');
  10.             yak.value = e;
  11.         }
  12.         </script>
  13.         <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
  14.         <meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
  15.         <meta name="vs_defaultClientScript" content="JavaScript">
  16.         <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
  17.     </HEAD>
  18.     <body MS_POSITIONING="GridLayout">
  19.         <form id="Form1" method="post" runat="server">
  20.             <asp:ListBox id="ListBox1" style="Z-INDEX: 103; LEFT: 232px; POSITION: absolute; TOP: 72px" runat="server" onChange="change(this.value);"></asp:ListBox>
  21.             <asp:TextBox id="TextBox3" style="Z-INDEX: 101; LEFT: 200px; POSITION: absolute; TOP: 208px"
  22.                 runat="server"></asp:TextBox>
  23.         </form>
  24.     </body>
  25. </HTML>

Good Luck;
Brandoe85 is offline   Reply With Quote
Old Apr 5th, 2005, 03:04 AM   #3
usamaalam
Frenzied Member
 
usamaalam's Avatar
 
Join Date: Nov 02
Location: Karachi
Posts: 1,267
usamaalam is on a distinguished road (10+)
Re: How to use server control in JavaScript

Thanks. It resolved my problem. I have two more questions.

My listbox is databound, and I have used DataTextField and DataValueField properties. When I get the value of ListBox in JavaScript function, it gives me DataValueField. I need to get the SelectedText of the listbox control.

Code:
thisList.DataSource = dtTemporary; // Bind with DataTable
thisList.DataTextField = "Name";
thisList.DataValueField = "ID";
thisList.DataBind();
Secondly, I have an ImageButton control for Delete and I have written code for Delete in aspx.cs file in the ImageButton Click event. Now I need to write some client-side validation code on the click of the button. When I call the function on click of ImageButton, application gives exception.

Code:
<asp:ImageButton id="deleteImageBox" runat="server" ImageUrl="images\btn_delete_off.gif" BorderStyle="None" OnClick='javascript:btnDelete_Click();'></asp:ImageButton>
__________________
The secret of creativity is knowing how to hide your sources...
usamaalam is offline   Reply With Quote
Reply

Go Back   VBForums > .NET > ASP.NET


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

Forum Jump


All times are GMT -5. The time now is 05:38 AM.





Acceptable Use Policy

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.