473,834 Members | 2,387 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Question about client-side added options to dropdownlist

I have some thing like this:

<body>
<form id="form1" runat="server">
<div>
<asp:DropDownLi st ID="uxTestDropD ownList" runat="server" />
<asp:Button ID="uxSubmitBut ton" runat="server" Text="Submit"
OnClick="uxSubm itButton_Click" />
</div>
<script type="text/javascript">
var ddl = document.getEle mentById("uxTes tDropDownList") ;
ddl.options[0] = new Option("Item1", "Item1");
ddl.options[1] = new Option("Item2", "Item2");
ddl.options[2] = new Option("Item3", "Item3");
</script>
</form>
</body>

And in uxSubmitButton_ Click, it's just simply:
Response.Write( uxTestDropDownL ist.SelectedVal ue);

The "Item1" ~ "Item3" have been successfully added to DropDownList, but when
I click on uxSubmitButton, nothing print on page after post back... How to
make this work? (I have set EnableEventVali dation="false" in page directive)

Thanks in advance!

Lei
Aug 1 '08 #1
7 1795
If you are going to load client side, you will have to use the Request
object to find the control, by name, and pull its value.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://gregorybeamer.spaces.live.com/lists/feed.rss

or just read it:
http://gregorybeamer.spaces.live.com/

*************** *************** **************
| Think outside the box! |
*************** *************** **************
"yanni" <ya*******@126. comwrote in message
news:u2******** ********@TK2MSF TNGP06.phx.gbl. ..
>I have some thing like this:

<body>
<form id="form1" runat="server">
<div>
<asp:DropDownLi st ID="uxTestDropD ownList" runat="server" />
<asp:Button ID="uxSubmitBut ton" runat="server" Text="Submit"
OnClick="uxSubm itButton_Click" />
</div>
<script type="text/javascript">
var ddl = document.getEle mentById("uxTes tDropDownList") ;
ddl.options[0] = new Option("Item1", "Item1");
ddl.options[1] = new Option("Item2", "Item2");
ddl.options[2] = new Option("Item3", "Item3");
</script>
</form>
</body>

And in uxSubmitButton_ Click, it's just simply:
Response.Write( uxTestDropDownL ist.SelectedVal ue);

The "Item1" ~ "Item3" have been successfully added to DropDownList, but
when I click on uxSubmitButton, nothing print on page after post back...
How to make this work? (I have set EnableEventVali dation="false" in page
directive)

Thanks in advance!

Lei
Aug 1 '08 #2
"yanni" <ya*******@126. comwrote in message
news:u2******** ********@TK2MSF TNGP06.phx.gbl. ..
The "Item1" ~ "Item3" have been successfully added to DropDownList, but
when I click on uxSubmitButton, nothing print on page after post back...
How to make this work? (I have set EnableEventVali dation="false" in page
directive)
The problem here is ViewState, which knows only about objects created
server-side.

So, you have two options:

1) Create the options server-side and use ViewState to reference them on
postback

2) Create the options client-side and use Request.Form["uxTestDropDown List"]
to reference them on postback
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Aug 1 '08 #3
all the browser posts back is the value. for the serverside control to
set a matching selected value, it must be in the list. if the server
knows the logic, it can add the dropdown value in OnInit, so the
selected value can be set (this woudl also allow validation to enabled).
your code could also look at the postback form collection, and add the
postback value in OnInint.

-- bruce (sqlwork.com)

yanni wrote:
I have some thing like this:

<body>
<form id="form1" runat="server">
<div>
<asp:DropDownLi st ID="uxTestDropD ownList" runat="server" />
<asp:Button ID="uxSubmitBut ton" runat="server" Text="Submit"
OnClick="uxSubm itButton_Click" />
</div>
<script type="text/javascript">
var ddl = document.getEle mentById("uxTes tDropDownList") ;
ddl.options[0] = new Option("Item1", "Item1");
ddl.options[1] = new Option("Item2", "Item2");
ddl.options[2] = new Option("Item3", "Item3");
</script>
</form>
</body>

And in uxSubmitButton_ Click, it's just simply:
Response.Write( uxTestDropDownL ist.SelectedVal ue);

The "Item1" ~ "Item3" have been successfully added to DropDownList, but when
I click on uxSubmitButton, nothing print on page after post back... How to
make this work? (I have set EnableEventVali dation="false" in page directive)

Thanks in advance!

Lei

Aug 1 '08 #4
viewstate is used to recreate the dropdown list on postback. its not
required if the list is built on postback in oninit. In fact its good
practice to disable viewstate to reduce page size.

-- bruce (sqlwork.com)

Mark Rae [MVP] wrote:
"yanni" <ya*******@126. comwrote in message
news:u2******** ********@TK2MSF TNGP06.phx.gbl. ..
>The "Item1" ~ "Item3" have been successfully added to DropDownList,
but when I click on uxSubmitButton, nothing print on page after post
back... How to make this work? (I have set
EnableEventVal idation="false" in page directive)

The problem here is ViewState, which knows only about objects created
server-side.

So, you have two options:

1) Create the options server-side and use ViewState to reference them on
postback

2) Create the options client-side and use
Request.Form["uxTestDropDown List"] to reference them on postback

Aug 1 '08 #5
"bruce barker" <no****@nospam. comwrote in message
news:eT******** ********@TK2MSF TNGP06.phx.gbl. ..
>>The "Item1" ~ "Item3" have been successfully added to DropDownList, but
when I click on uxSubmitButton, nothing print on page after post back...
How to make this work? (I have set EnableEventVali dation="false" in page
directive)

The problem here is ViewState, which knows only about objects created
server-side.

So, you have two options:

1) Create the options server-side and use ViewState to reference them on
postback

2) Create the options client-side and use
Request.Form["uxTestDropDown List"] to reference them on postback

viewstate is used to recreate the dropdown list on postback. its not
required if the list is built on postback in oninit. In fact its good
practice to disable viewstate to reduce page size.
How will this help since, in the OP's case, the list is built in client-side
JavaScript...?
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Aug 1 '08 #6
The OP has all of the values added client side, which negates OnInit(),
unless you are talking something other than the server side event handler.
Pulling the value from the form collection is his best option, as far as I
can see.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://gregorybeamer.spaces.live.com/lists/feed.rss

or just read it:
http://gregorybeamer.spaces.live.com/

*************** *************** **************
| Think outside the box! |
*************** *************** **************
"bruce barker" <no****@nospam. comwrote in message
news:Ov******** ********@TK2MSF TNGP06.phx.gbl. ..
all the browser posts back is the value. for the serverside control to set
a matching selected value, it must be in the list. if the server knows the
logic, it can add the dropdown value in OnInit, so the selected value can
be set (this woudl also allow validation to enabled). your code could also
look at the postback form collection, and add the postback value in
OnInint.

-- bruce (sqlwork.com)

yanni wrote:
>I have some thing like this:

<body>
<form id="form1" runat="server">
<div>
<asp:DropDownLi st ID="uxTestDropD ownList" runat="server" />
<asp:Button ID="uxSubmitBut ton" runat="server" Text="Submit"
OnClick="uxSub mitButton_Click " />
</div>
<script type="text/javascript">
var ddl = document.getEle mentById("uxTes tDropDownList") ;
ddl.options[0] = new Option("Item1", "Item1");
ddl.options[1] = new Option("Item2", "Item2");
ddl.options[2] = new Option("Item3", "Item3");
</script>
</form>
</body>

And in uxSubmitButton_ Click, it's just simply:
Response.Write (uxTestDropDown List.SelectedVa lue);

The "Item1" ~ "Item3" have been successfully added to DropDownList, but
when I click on uxSubmitButton, nothing print on page after post back...
How to make this work? (I have set EnableEventVali dation="false" in page
directive)

Thanks in advance!

Lei
Aug 1 '08 #7
IC. Thanks guys.

Lei
Aug 2 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1426
by: Tony Johansson | last post by:
Hello! I'm reading a book about C++ and there is something that I don't understand so I ask you. I have marked the section from the book that is of intertest by tagging it with BOOK START HERE and ending with BOOK ENDING HERE. All that text between is just a copy from the book. My question come after the text section. The book says
7
3374
by: CT | last post by:
Hi, This might seem like a basic question but I have some doubts, please humour me. I have a client-server application using java where each client on each machine needs to directly communicate directly with the database. Do I need a separate db2 connect on each such machine. Please advice.
6
2123
by: rodchar | last post by:
Hey all, I'm trying to understand Master/Detail concepts in VB.NET. If I do a data adapter fill for both customer and orders from Northwind where should that dataset live? What client is responsible for instantiating the orders class? Would it be the ui layer or the master class in the business layer? thanks,
1
1552
by: Brian Henry | last post by:
Hello, I was tring to learn socket's (being i never used them before) and have a simple question. I want to create a listner that will get any data recieved and print it out. I've been able to get it to recieve only one line of data, but the next one i send to it wont be printed like the 1st one. I had a listner running in a thread, does anyone have a simple listner code example that would show how to have a tcplistner thread running...
11
4217
by: pshindle | last post by:
We have several machines currently running the DB2 V7 Run-time Client that we would like to actually be running the App Dev Client. To 'upgrade' (within the same version) this client software can we simply install the App Dev Client on 'top of' the Run-time Client? Will the install routine uninstall the Run-time Client under the covers during the install of the App Dev Client? Also, is this type of 'upgrade' possible/supported during a...
2
1237
by: et | last post by:
I am new to asp.net. I am writing a program that will revolve around an extensive client database, and wonder what the best way to design the program is, using classes. I have about 10 different sections, or categories if you will, about a client. For instance, some clients have data regarding our Estate Planning section, some clients have data regarding our Real Estate section, etc. Would it be better to have one object that...
1
1346
by: Frank Millman | last post by:
Hi all I am developing a multi-user business/accounting application. It is coming along nicely :-), though rather slowly :-( I have hit an issue which will require a lot of changes to the code I have written so far, together with an increase in complexity and all the bad things that follow from that. Before I go ahead and make the changes, I thought I would bounce it off the group and see if there is a simpler approach.
10
2114
by: Robert | last post by:
I am an attorney in a non-profit organization and a self-taught programmer. I'm trying to create a client db that will allow me to search for potential conflicts of interest based either on Social Security # or on Last Name. I've created two different tables with the following fields in each table: ClientInfo Client# (primary key) First Name Middle Name Last Name
4
3609
by: Engineerik | last post by:
I am trying to create a socket server which will listen for connections from multiple clients and call subroutines in a Fortran DLL and pass the results back to the client. The asynchronous socket client and asynchronous socket server example code provided in the .NET framework developers guide is a great start but I have not dealt with sockets before and I am struggling with something. From what I can tell the sample server code ...
3
1183
by: CeJay | last post by:
Hi All Ok this is a bit of a doozy for me. Work related question, I have been tasked with sorting out this issue at work, but don't really have much background in this field, but theres no one else in my team that can do it. Bit of a background on the problem. At work we have a server and a client machine, They are both running on Windows Server 2000. They both have on them proprietry software for the client which uses MSSQL. Late last...
0
9796
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9642
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10500
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10213
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7753
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5624
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5789
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4422
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3078
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.