Having a problem...
I have a Bound DropDownList to a SQL table, when selectedindex is changed it is suppose to update the text boxes and labels in the update panel. It is working but the page is still refreshing? This latest code, I tried to move the Dropdownlist out of the Update Panel to see if that was the problem. It wasn't... I get the same results. an entire page refresh? I was watching this how to video ASP.NET AJAX: A demonstration of ASP.NET AJAX They make a To do list using gridview and dropdownlist, but a data table instead of a SQLConnection. Can anyone see why this isn't working?
Thanks,
Jason
Here is the code behind page
I have a Bound DropDownList to a SQL table, when selectedindex is changed it is suppose to update the text boxes and labels in the update panel. It is working but the page is still refreshing? This latest code, I tried to move the Dropdownlist out of the Update Panel to see if that was the problem. It wasn't... I get the same results. an entire page refresh? I was watching this how to video ASP.NET AJAX: A demonstration of ASP.NET AJAX They make a To do list using gridview and dropdownlist, but a data table instead of a SQLConnection. Can anyone see why this isn't working?
Thanks,
Jason
Code:
<%@ Page Title="" Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="AddAjaxTest.aspx.vb" Inherits="Default2" %>
<%@ Register assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" namespace="System.Web.UI" tagprefix="asp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true">
</asp:ScriptManager>
<asp:DropDownList ID="DDLVendorName" runat="server"
AppendDataBoundItems="True"
DataSourceID="SqlVendorList" DataTextField="NAME"
DataValueField="VENDORID"
OnSelectedIndexChanged="DDLVendorName_SelectedIndexChanged" AutoPostBack="True">
</asp:DropDownList>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" >
<ContentTemplate>
<table style="width:656px">
<tr>
<td style="height: 20px; border-top-width: thin; border-left-width: thin; border-left-color: black; border-bottom-width: thin; border-bottom-color: black; border-top-color: black; border-right-width: thin; border-right-color: black; width: 113px;">
Vendor Name</td>
<td style="height: 20px; border-top-width: thin; border-left-width: thin; border-left-color: black; border-bottom-width: thin; border-bottom-color: black; border-top-color: black; border-right-width: thin; border-right-color: black; width: 200px;">
</td>
<td style="height: 20px; border-top-width: thin; border-left-width: thin; border-left-color: black; border-bottom-width: thin; border-bottom-color: black; border-top-color: black; border-right-width: thin; border-right-color: black; width: 88px;">
Account Code</td>
<td style="width: 25px; height: 20px; border-top-width: thin; border-left-width: thin; border-left-color: black; border-bottom-width: thin; border-bottom-color: black; border-top-color: black; border-right-width: thin; border-right-color: black;">
<asp:DropDownList ID="DDLAcountCode" runat="server">
<asp:ListItem></asp:ListItem>
<asp:ListItem>740</asp:ListItem>
<asp:ListItem>743</asp:ListItem>
<asp:ListItem>930</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td style="height: 21px; border-top-width: thin; border-left-width: thin; border-left-color: black; border-bottom-width: thin; border-bottom-color: black; border-top-color: black; border-right-width: thin; border-right-color: black; width: 113px;">
Phone #</td>
<td style="height: 21px; width: 200px;">
<asp:Label ID="lblPhoneNumber" runat="server"></asp:Label>
</td>
<td style="height: 21px; border-left-width: thin; border-left-color: gray; width: 88px;">
PO Number</td>
<td style="width: 25px; height: 21px">
<asp:Label ID="lblPONumber" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td style="height: 21px; border-top-width: thin; border-left-width: thin; border-left-color: black; border-bottom-width: thin; border-bottom-color: black; border-top-color: black; border-right-width: thin; border-right-color: black; width: 113px;">
Fax #</td>
<td style="height: 21px; width: 200px;">
<asp:Label ID="lblFaxNumber" runat="server"></asp:Label>
</td>
<td style="height: 21px; width: 88px;">
Order #</td>
<td style="width: 25px; height: 21px">
<asp:Label ID="lblOrderNumber" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td style="height: 21px; width: 113px;">
Account Number</td>
<td style="height: 21px; width: 200px;">
<asp:Label ID="lblAccountNumber" runat="server"></asp:Label>
</td>
<td style="height: 21px; width: 88px;">
Order Date</td>
<td style="width: 25px; height: 21px;">
<asp:TextBox ID="txtOrderDate" runat="server" Width="64px"></asp:TextBox>
</td>
</tr>
<tr>
<td style="height: 24px; width: 113px;">
Confirmation #</td>
<td style="height: 24px; width: 200px;">
<asp:TextBox ID="txtConfirmationNumber" runat="server" Width="184px"></asp:TextBox>
</td>
<td style="height: 24px; width: 88px;">
</td>
<td style="width: 25px; height: 24px;">
</td>
</tr>
</table>
<br />
<br />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="DDLVendorName"
EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
<asp:SqlDataSource ID="SqlVendorList" runat="server"
ConnectionString="Data Source=server;Initial Catalog=LabPO;Persist Security Info=True;User ID=sa;Password=xxxx"
SelectCommand="SELECT * FROM [VENDORS] ORDER BY [NAME]"></asp:SqlDataSource>
<br />
<br />
<br />
<br />
<table style="width: 100%">
<tr>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
</tr>
</table>
</asp:Content>
Here is the code behind page
Code:
Protected Sub DDLVendorName_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DDLVendorName.SelectedIndexChanged
Dim MyConnection As System.Data.SqlClient.SqlConnection
Dim MyDataAdapter As SqlClient.SqlDataAdapter
Dim MyDataTable As New DataTable
'Dim MyDataRow As DataRow
Try
Dim strSQL As String = "SELECT * from vendors where vendorID =" & Me.DDLVendorName.SelectedValue
' Connect and fill the DataTable
MyConnection = New System.Data.SqlClient.SqlConnection("Data Source=server;Initial Catalog=LabPO;Persist Security Info=True;User ID=sa;Password=xxxx")
MyConnection.Open()
MyDataAdapter = New SqlClient.SqlDataAdapter(strSQL, MyConnection)
MyDataAdapter.Fill(MyDataTable)
Me.lblFaxNumber.Text = MyDataTable.Rows.Item(0).Item("FAX")
Me.lblPhoneNumber.Text = MyDataTable.Rows.Item(0).Item("phone")
Me.lblPONumber.Text = MyDataTable.Rows.Item(0).Item("PONumber")
Me.lblAccountNumber.Text = MyDataTable.Rows.Item(0).Item("contact")
Catch ex As Exception
'lblError.Text = "Error in DDLVendorName: " & ex.Message
End Try
End Sub