[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Get value from dropdownlist

Posted on 2010-11-10
10
Medium Priority
?
1,320 Views
Last Modified: 2012-06-21
Hi!
        I'm building a website in asp.net and I must use a free control called Obout Ajax (very similar to microsoft updatepanel)
I need to get the "selectedvalue" from the second dropdownlist (making a postback) but I always return "nothing"
Can you help me?

I leave a ZIP with the code and \Bin library



<%@ Page Language="VB" AutoEventWireup="false" Inherits="OboutInc.oboutAJAXPage" EnableEventValidation="false" %>
<%@ Register TagPrefix="oajax" Namespace="OboutInc" Assembly="obout_AJAXPage" %>
<%@ Register TagPrefix="obout" Namespace="Obout.Interface" Assembly="obout_Interface" %>

<script language="VB" runat="server">

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        For i = 1 To 3
            txtSheet.Items.Add("Item " & i)
        Next

    End Sub
    
    Public Sub GetData(ByVal MyThing As String)
        
        For i = 1 To 10
        
            ddlColumns.Items.Add(MyThing & i)
            ddlColumns.Enabled = True
            UpdatePanel("CallbackColumn")
            
        Next
        
    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        LabelResult01.Text = "And the selected value is: "
        LabelResult02.Text = ddlColumns.SelectedValue
    End Sub
</script>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Get data without reload</title>

    <script type="text/javascript">
        	
		function GetColumns() 
			{
                var mything = txtSheet.value(); 
			    
			    ob_post.AddParam("MyThing", mything);
			    ob_post.post(null, "GetData", function() { });
			}
        
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <oajax:CallbackPanel ID="CallbackSheet" runat="server">
        <Content>
        
            <obout:OboutDropDownList ID="txtSheet" runat="server" AppendDataBoundItems="true"
                Enabled="true">
                <ClientSideEvents OnSelectedIndexChanged="GetColumns" />
            </obout:OboutDropDownList>
        </Content>
    </oajax:CallbackPanel>
    <oajax:CallbackPanel ID="CallbackColumn" runat="server" RenderMethod="OnCallback">
        <Content>
            <obout:OboutDropDownList ID="ddlColumns" runat="server" AppendDataBoundItems="true"
                Enabled="False">
            </obout:OboutDropDownList>
        </Content>
    </oajax:CallbackPanel>
    <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
    <br />
    <br />
    <asp:label ID="LabelResult01" runat="server" Text="Label1" />
    <asp:label ID="LabelResult02" runat="server" Text="Label2"/>
    </form>
</body>
</html>

Open in new window

WebSiteExample.zip
0
Comment
Question by:ShermanGuti
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
10 Comments
 
LVL 8

Expert Comment

by:guvera
ID: 34109262
try to give AutoPostback = "true" in your second drop down
0
 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 34109701
On every PostBack, the code in Page_Load event is executing which clears the dropdownlist contents.

Wrap that code in Page_Load inside a IsPostBack check
Raj
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Not IsPostBack Then
            For i = 1 To 3
                txtSheet.Items.Add("Item " & i)
            Next

        End If
    End Sub

Open in new window

0
 

Author Comment

by:ShermanGuti
ID: 34111681
guvera, RajkumarGS
I had already tried and did not work
0
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 

Author Comment

by:ShermanGuti
ID: 34111701
I have attached a basic example in a zip file WebSiteExample.zip


thank you!
0
 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 34113133
I downloaded and checked your project.

On button click, second dropdownlist lost its values as if page is loading for the first time. That's why selectedvalue always returns ''

The only difference between dropdownlist is that second is disabled. I am not familiar with Obout Ajax. You need to findout what Obout Ajax is doing here !? Enabled dropdownlist preserves its data, while disabled dropdownlist loses it.

Anyway you need my first suggestion - http:#34109701

If this is not working, try javascript code to do the stuff.

Raj

Raj
0
 

Author Comment

by:ShermanGuti
ID: 34114881
If A get the value with javascript, is there a way to send it to server-side while I make the postback?
0
 

Author Comment

by:ShermanGuti
ID: 34116697
Well now dropdownlist is enable and "If not Postback" is added but doesn't work

look my code

<%@ Page Language="VB" AutoEventWireup="false" Inherits="OboutInc.oboutAJAXPage"
    EnableEventValidation="false" %>

<%@ Register TagPrefix="oajax" Namespace="OboutInc" Assembly="obout_AJAXPage" %>
<%@ Register TagPrefix="obout" Namespace="Obout.Interface" Assembly="obout_Interface" %>

<script language="VB" runat="server">

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        
        If Not IsPostBack Then
            For i = 1 To 3
                txtSheet.Items.Add("Item " & i)
            Next
        End If

    End Sub
    
    Public Sub GetData(ByVal MyThing As String)
        
        For i = 1 To 10
        
            ddlColumns.Items.Add(MyThing & i)
            ddlColumns.Enabled = True
            UpdatePanel("CallbackColumn")
            
        Next
        
    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)

        LabelResult01.Text = "And the selected value is: "
        LabelResult02.Text = ddlColumns.SelectedValue

    End Sub
</script>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Get data without reload</title>

    <script type="text/javascript">

function GetColumns()
{


			    var IndexValue = document.getElementById('txtSheet').selectedIndex;
			    var mything = document.getElementById('txtSheet').options[IndexValue].value;
			    
			    ob_post.AddParam("MyThing", mything);
			    ob_post.post(null, "GetData", function() { });

}


    </script>

</head>
<body>
    <form id="form1" runat="server">
    <oajax:CallbackPanel ID="CallbackSheet" runat="server">
        <Content>
            <asp:DropDownList ID="txtSheet" runat="server" onchange="GetColumns();">
            </asp:DropDownList>
        </Content>
    </oajax:CallbackPanel>
    <oajax:CallbackPanel ID="CallbackColumn" runat="server">
        <Content>
            <asp:DropDownList ID="ddlColumns" runat="server">
            </asp:DropDownList>
        </Content>
    </oajax:CallbackPanel>
    <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
    <br />
    <br />
    <asp:Label ID="LabelResult01" runat="server" Text="resultado01" />
    <asp:Label ID="LabelResult02" runat="server" Text="resultado02" />
    <br />
 
    </form>
</body>
</html>

Open in new window

0
 

Accepted Solution

by:
ShermanGuti earned 0 total points
ID: 34124866
No one could help me.
I fix my problem by my self
I replaced obout ajax with ms ajax



<%@ Page Language="VB" AutoEventWireup="true"  %>
<%@ Register TagPrefix="oajax" Namespace="OboutInc" Assembly="obout_AJAXPage" %>
<%@ Register TagPrefix="obout" Namespace="Obout.Interface" Assembly="obout_Interface" %>

<script language="VB" runat="server">

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        For i = 1 To 3
            txtSheet.Items.Add("Item " & i)
        Next

    End Sub
   
    Public Sub txtSheet_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
       
        For i = 1 To 10
       
            ddlColumns.Items.Add(txtSheet.SelectedValue & i.ToString())
            ddlColumns.Visible = True
           
        Next
       
    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        LabelResult01.Text = "And the selected value is: "
        LabelResult02.Text = ddlColumns.SelectedValue
    End Sub
</script>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Get data without reload</title>
</head>
<body>
    <form id="form1" runat="server">

    <asp:ScriptManager runat="Server" />

    <asp:UpdatePanel ID="CallbackSheet" runat="server">
        <ContentTemplate>
       
            <obout:OboutDropDownList ID="txtSheet" runat="server" AppendDataBoundItems="true" AutoPostBack="true"
                Enabled="true" OnSelectedIndexChanged="txtSheet_SelectedIndexChanged">
            </obout:OboutDropDownList>

            <br />

            <obout:OboutDropDownList ID="ddlColumns" runat="server" AppendDataBoundItems="true"
                Visible="false">
            </obout:OboutDropDownList>

           
        </ContentTemplate>
    </asp:UpdatePanel>
    <br /><br />            
    <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
       
    <br />
    <br />
    <asp:label ID="LabelResult01" runat="server" Text="Label1" />
    <asp:label ID="LabelResult02" runat="server" Text="Label2"/>
    </form>
</body>
</html>
0
 

Author Closing Comment

by:ShermanGuti
ID: 34153372
By my self
0
 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 34153432
Nice to see you got the solution.

I am having experience only in Ajax not in 'obout ajax'. Thats' why I am unable to assist you.

Best Regards
Raj
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question