Solved

Get value from dropdownlist

Posted on 2010-11-10
10
1,280 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

Question has a verified solution.

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

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

679 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