Solved

Get value from dropdownlist

Posted on 2010-11-10
10
1,256 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
Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

910 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

21 Experts available now in Live!

Get 1:1 Help Now