Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6353251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:22:45+00:00 2026-05-24T22:22:45+00:00

Hi I’m trying to utilize more java-script, jquery, ajax in my asp code. So

  • 0

Hi I’m trying to utilize more java-script, jquery, ajax in my asp code. So for a project I built this field chooser using java-script. enter image description here

 <asp:ListBox ID="lb1" runat="server" Height="400px" Width="170px"></asp:ListBox>

 <input type="button" id="_b_Add" value="Add >" onclick="add();" style="padding:5px; margin-left:5px; margin-top:15px; width: 131px;" />

 <input type="button" id="_b_Rem" value="< Remove" onclick="remove();" style="padding:5px; margin-top: -25px; margin-left:5px; width: 131px;" />

 <input type="button" value="Up" onclick="moveUp(document.getElementById('lb2'));" style="padding:5px; margin-left:5px; width: 131px;" />

 <input type="button" value="Down" onclick="moveDown();" style="padding:5px; margin-left:5px; margin-top: -25px; width: 131px;" />

 <asp:Button ID="_b_Reset" runat="server" Text="Reset" Width="131px" 
                    style="padding:5px; margin-left:5px; margin-top:40px;" 
                    onclick="_b_Reset_Click"  />

 <asp:Button ID="_b_Run" runat="server" Text="Run" Width="131px" 
                    style="padding:5px; margin-left:5px; margin-top:10px;" 
                    onclick="_b_Run_Click"  />

 <asp:ListBox ID="lb2" runat="server" Height="400px" Width="170px"                       AppendDataBoundItems="True" Enabled="False"></asp:ListBox>

and here is the important javascript:

            function prom() { { $.prompt('Maximum Number of Custom Types is 14 '); } }

        function add() {
            var opt = document.createElement("option");
            var sel = document.getElementById("lb1").selectedIndex;

            if ((document.getElementById("lb1").selectedIndex) != -1 && document.getElementById("lb2").length < 14) {
                document.getElementById("lb2").options.add(opt);
                opt.text = (document.getElementById("lb1").options[document.getElementById("lb1").selectedIndex].text);
                opt.value = (document.getElementById("lb1").value);

                document.getElementById("lb1").options.remove((document.getElementById("lb1").selectedIndex));
                document.getElementById("lb1").options.SelectedIndex = sel;

            }
            else {
                prom();
            }
        }
        function remove() {
            var opt = document.createElement("option");
            var sel = document.getElementById("lb2").selectedIndex;

            if ((document.getElementById("lb2").selectedIndex) != -1) {
                document.getElementById("lb1").options.add(opt);
                opt.text = (document.getElementById("lb2").options[document.getElementById("lb2").selectedIndex].text);
                opt.value = (document.getElementById("lb2").value);
            }

            document.getElementById("lb2").options.remove((document.getElementById("lb2").selectedIndex));
            document.getElementById("lb2").options.selectedIndex = sel;
        }

EDIT ***

Testing the values in lb2

    foreach (var item in lb2.Items.Cast<ListItem>()) 
    {
        TextBox1.Text += (item.Value).ToString();
        i++;
    }

This works fine on the lb1 not but when the item have been added client side its no good.

Basically now on run the values of lb2 should be iterated and fed into my report class. However I quickly realized that the changes made by the java script to lb2 are not reflected in the viewstate when the “_b_Run_Click” event is fired. So after digging around a bit I seem to get the impression that the solution is to use a hidden field … My question is (being a js noob) how exactly do you do that and is there an more elegant alternative ?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T22:22:46+00:00Added an answer on May 24, 2026 at 10:22 pm

    Latest answer

    I believe your problem is because Disabled controls are not submitted in the form post. Remove Enabled="False" from lb2 and try again.

    You can prevent users from clicking on that control by onclick/onfocus and setting focus to another control. Or using a hidden box to store the values and a div to display the values.

    Older answer attempt below

    Are you binding in the Page_Load without if (!IsPostBack)?

    This will override any values in the listbox before the button event reads them

    public void Page_Load
    {
        lb2.DataSource = ...
        lb2.DataBind();
    }
    

    If that is the problem, this will fix it.

    public void Page_Load
    {
        if (!IsPostBack)
        {
            lb2.DataSource = ...
            lb2.DataBind();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I am trying to loop through a bunch of documents I have to put
I have some data like this: 1 2 3 4 5 9 2 6

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.