Solved

Get value from dropdownlist

Posted on 2010-11-10
10
1,296 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

707 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