Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.1
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 6th, 2004, 11:39 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

happy to be helpful dear friend.

Always:),
Hovik Melkomian.
 
Old April 8th, 2004, 07:49 AM
Authorized User
 
Join Date: Jul 2003
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to sankar
Default

Hi there,
I tried the following file to use your technique. Perhaps I've done all wrong....

This is the file I created to test...
<%@ Page Language="VB"%>
<html>
<head>
<title>Test Dropdown list</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">
    function DisplayValue()
    {
        var index_value;
        index_value = frm.elements['list'].selectedIndex;
        if (index_value = 1)
            alert("1");
        if (index_value = 2)
            alert("2");
    }
</script>
</head>
<body>
<form name="frm" id="frm" method="post" runat="server">
<asp:dropdownlist AutoPostBack="false" BackColor="#33FFFF" CssClass="bigdroplisttext" ForeColor="#000000" ID="list" OnSelectedIndexChanged="JavaScript:DisplayValue(); " runat="server">
    <asp:listitem Text="Name1" Value="1"></asp:listitem>
    <asp:listitem Text="Name2" Value="2"></asp:listitem>
    <asp:listitem Text="Name3" Value="3"></asp:listitem>
    <asp:listitem Text="Name4" Value="4"></asp:listitem>
</asp:dropdownlist>
</form>
</body>
</html>

It is giving me the following error:
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30456: 'JavaScript' is not a member of 'ASP.Test_aspx'.

So, how do I do it then?
Quote:
quote:Originally posted by melvik
 happy to be helpful dear friend.

Always:),
Hovik Melkomian.
Sankar Sengupta
Striving for the BEST
 
Old April 8th, 2004, 01:55 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Try:

Sub Page_Load(..)
  '"this" passes a reference to the drop down list
  DropDownList1.Attributes.Add("onchange", "DisplayValue(this);")
End Sub

Javascript:

function DisplayValue(objList) {
  var index_value = objList.selectedIndex;

  if (index_value == 1)
    alert("1");

  if (index_value == 2)
    alert("2");
}

It's been a while since I did Javascript so forgive me if it is a little "rusty."

Hope this helps.
 
Old April 12th, 2004, 01:18 AM
Authorized User
 
Join Date: Jul 2003
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to sankar
Default

Hey,
Thanx a lot buddy. This is workin well. I have only one question. I want to set some value in a server side hidden field declared as:
<asp:textbox ID="emailid" Visible="false" runat="server" />
But as soon as I am trying to assign a value to this field using JavaScript like:
emailid.innerHTML = "some email address";
It says 'emailid' is undefined.
How can I store the value in a server-side hidden field control?
Thx in adv.
Quote:
quote:Originally posted by bmains
 Try:

Sub Page_Load(..)
'"this" passes a reference to the drop down list
DropDownList1.Attributes.Add("onchange", "DisplayValue(this);")
End Sub

Javascript:

function DisplayValue(objList) {
var index_value = objList.selectedIndex;

if (index_value == 1)
    alert("1");

if (index_value == 2)
    alert("2");
}

It's been a while since I did Javascript so forgive me if it is a little "rusty."

Hope this helps.
Sankar Sengupta
Striving for the BEST
 
Old April 12th, 2004, 01:56 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

You can only reference a field directly like that (emailid.innerHTML) in VBScript. There are several ways you can do this. I think you can do document.all('field name'). Like I said, I'm a little rusty, but you have to reference a collection field to retrieve a reference to the object. There are actually a couple of ways to reference a control, which vary by browser.

Brian
 
Old October 13th, 2004, 07:18 AM
Registered User
 
Join Date: Oct 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

I tried useing the code above to put the javascript validation for dropdown.

I get a wierd error

Compiler Error Message: CS1026: ) expected
on the line where the drop down is declared, i.e. following code line.

<asp:dropdownlist AutoPostBack="false" BackColor="#33FFFF" ForeColor="#000000" ID="list" OnSelectedIndexChanged="DisplayValue();" runat="server">

I have the DisplayValue() function in the javascript block at start of page.

Please help.

 
Old October 13th, 2004, 07:33 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

OnSelectedIndexChanged is looking for a server-side event. This statement DropDownList1.Attributes.Add("onchange", "DisplayValue(this);") actually links the dropdown to the javascript event. Remove the OnSelectedIndexChanged.

Brian
 
Old October 13th, 2004, 07:33 AM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 449
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to r_ganesh76
Default

if you set the server side visible = false, the control will not come to the client side. in the HTML view of the page, you wont be able to see the control. You can use <input type="hidden" runat="server" id="emailid"> insted.You can use this both in the client side and the server side also.

Hope this helps..

Quote:
quote:Originally posted by sankar
 Hey,
Thanx a lot buddy. This is workin well. I have only one question. I want to set some value in a server side hidden field declared as:
<asp:textbox ID="emailid" Visible="false" runat="server" />
But as soon as I am trying to assign a value to this field using JavaScript like:
emailid.innerHTML = "some email address";
It says 'emailid' is undefined.
How can I store the value in a server-side hidden field control?
Thx in adv.
Quote:
quote:Originally posted by bmains
 Try:

Sub Page_Load(..)
'"this" passes a reference to the drop down list
DropDownList1.Attributes.Add("onchange", "DisplayValue(this);")
End Sub

Javascript:

function DisplayValue(objList) {
var index_value = objList.selectedIndex;

if (index_value == 1)
    alert("1");

if (index_value == 2)
    alert("2");
}

It's been a while since I did Javascript so forgive me if it is a little "rusty."

Hope this helps.
Sankar Sengupta
Striving for the BEST
Regards
Ganesh
 
Old October 13th, 2004, 11:04 PM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 449
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to r_ganesh76
Default

Use a client side hidden control insted of the asp:textbox. Controls invisible at server side will not come to the client side.


I had posted this answer below. but it never came in the list

Quote:
quote:Originally posted by sankar
 Hey,
Thanx a lot buddy. This is workin well. I have only one question. I want to set some value in a server side hidden field declared as:
<asp:textbox ID="emailid" Visible="false" runat="server" />
But as soon as I am trying to assign a value to this field using JavaScript like:
emailid.innerHTML = "some email address";
It says 'emailid' is undefined.
How can I store the value in a server-side hidden field control?
Thx in adv.
Quote:
quote:Originally posted by bmains
 Try:

Sub Page_Load(..)
'"this" passes a reference to the drop down list
DropDownList1.Attributes.Add("onchange", "DisplayValue(this);")
End Sub

Javascript:

function DisplayValue(objList) {
var index_value = objList.selectedIndex;

if (index_value == 1)
    alert("1");

if (index_value == 2)
    alert("2");
}

It's been a while since I did Javascript so forgive me if it is a little "rusty."

Hope this helps.
Sankar Sengupta
Striving for the BEST
Regards
Ganesh





Similar Threads
Thread Thread Starter Forum Replies Last Post
Reloading page with Ctrl+F5 aliirfan84 ASP.NET 2.0 Professional 1 October 10th, 2007 07:19 AM
AJAX problem - the whole page is reloading geoko Ajax 1 June 7th, 2006 01:39 PM
reloading a page hubbe ASP.NET 1.0 and 1.1 Basics 0 April 13th, 2006 01:46 PM
Reloading page when option selected in dropdown chandrasekhar200 Beginning PHP 1 March 10th, 2006 04:52 AM
Page Reloading mahulda ASP.NET 1.0 and 1.1 Basics 5 April 21st, 2004 10:22 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.