| |

VerySource

 Forgot password?
 Register
Search
View: 1610|Reply: 11

Client-side JavaScript changes the items of the asp.net Dropdownlist control, how to get the selected value in the backg

[Copy link]

3

Threads

10

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 United States

Post time: 2020-1-25 08:00:01
| Show all posts |Read mode
Similar to the city list, there is no item when initializing. According to customer selection, javascript fills the list. After the form is submitted, how does the .cs background code obtain the value of DropDownList?
Reply

Use magic Report

0

Threads

322

Posts

115.00

Credits

Newbie

Rank: 1

Credits
115.00

 China

Post time: 2020-2-13 13:00:01
| Show all posts
Request.Form ["name"]
But it takes some effort to save the options
Reply

Use magic Report

0

Threads

8

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-2-13 14:00:01
| Show all posts
After the client assigns the value of the dropdownlist, the background code can directly read it with selectedvalue.
Reply

Use magic Report

0

Threads

12

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-3-5 20:45:01
| Show all posts
Use client controls.
Reply

Use magic Report

0

Threads

58

Posts

32.00

Credits

Newbie

Rank: 1

Credits
32.00

 China

Post time: 2020-3-6 16:00:01
| Show all posts
Request.Form ["dropdownlistId"]
Reply

Use magic Report

0

Threads

17

Posts

14.00

Credits

Newbie

Rank: 1

Credits
14.00

 Netherlands

Post time: 2020-3-8 10:00:01
| Show all posts
Oh, due to the characteristics of the Dropdownlist control, if it is a value assigned by the front-end JS, the background code cannot directly read the value of the Dropdownlist, and the landlord will find that the value of the Dropdownlist has returned to the initial spatiotemporal state.
The solution is:
Add a TextBox file box and make it invisible. Then select Dropdownlist, use js to assign the value to the TextBox, and read the value in the TextBox in the background when submitting.
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-3-8 23:15:02
| Show all posts
The foreground is saved with <input type = "hidden" id = "txta" name = "txta" runat = "server" />.
Txta.Value is used in the background.
Reply

Use magic Report

0

Threads

17

Posts

14.00

Credits

Newbie

Rank: 1

Credits
14.00

 China

Post time: 2020-3-9 09:15:02
| Show all posts
Correction: TextBox cannot be set to not hidden, so the background cannot read the value of the TextBox, ^ _ ^ but the foreground color of the TextBox can be set to the same color as the page background to achieve the "invisible" effect.

// Add a foreground event to the background Page_Load:
DropDownList1.Attributes.Add ("onchange", "ToTextBox ()");


// Decisions at the front desk:
function ToTextBox () {
        document.getElementById ("TextBox1"). value = document.all ("DropDownList1"). value;
    }
Reply

Use magic Report

0

Threads

17

Posts

14.00

Credits

Newbie

Rank: 1

Credits
14.00

 China

Post time: 2020-3-9 11:45:01
| Show all posts
Oh, in the waysolowebwolfbrother said, defining a hidden input is also an option!
Reply

Use magic Report

3

Threads

10

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

 Author| Post time: 2020-4-13 18:30:01
| Show all posts
Too much effort, decided to use the server side
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list