Solved

Get value from dropdownlist

Posted on 2010-11-10
10
1,244 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
  • 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
 

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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
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…

758 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now