473,473 Members | 2,185 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Dropdownlist connect using Ajax when postback reset to first list

4 New Member
Hi
I have a problem on Dropdownlist that connect database
and retrieve data by Ajax.I write javascript like this

-------------------------------------------------------------------------
function ManageYear_onchange(machinetype)
{

var iManageYear=document.forms[0].ddlManageYear.selectedIndex;
var vManageYear=document.forms[0].ddlManageYear[iManageYear].value;
clearDll("ddlEquipmentID");
clearDll("ddlVendor");
if(iManageYear!=0)
{
AjaxFile.getEquipmentid(vManageYear,machinetype, GetEquipmentRecords_CallBack);
}
else
{
document.getElementById("ddlEquipmentID").selected Index=0;
document.getElementById("ddlVendor").selectedIndex =0;
return
}

}

function GetEquipmentRecords_CallBack(response)
{
var ds = response.value;
var i = 0;
var iLength = 0;
if (response.error != null){
return;
}
if ((ds.Tables != null) && (ds.Tables[0].Rows.length > 0))
{
//insert data to dropdown
for(i=0; i<ds.Tables[0].Rows.length; i++)
{
document.getElementById("ddlEquipmentID").options. add(new Option(ds.Tables[0].Rows[i]["EquipmentName"],ds.Tables[0].Rows[i]["EquipmentID"]))
}
}
}

function clearDll(ddlname)
{
iLength=document.getElementById(ddlname).options.l ength;
for(i=0; i<iLength; i++)
{
document.getElementById(ddlname).options[0] = null;
}
document.getElementById(ddlname).options.add(new Option("--Please select--",0));

}
-------------------------------------------------------------------------
and i insert ManageYear_onchange() at code behind like this

-------------------------------------------------------------------------
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Ajax.Utility.RegisterTypeForAjax(GetType(AjaxFile) )
If Not Me.IsPostBack Then
Me._MachineType = Request.QueryString("MachineType")
ddlManageYear.SelectedValue = clsUtil.DateTimeNow.Year
ddlManageYear.Attributes.Add("onchange", "return ManageYear_onchange('" & Me._MachineType & "');")
Me.RegisterStartupScript("startup", "<script> ManageYear_onchange('" & Me._MachineType & "');</script>")
End If
End Sub
-------------------------------------------------------------------------

on Ajax page i connect to server and send dataset like this

-------------------------------------------------------------------------
<Ajax.AjaxMethod()> _
Public Function getEquipmentid(ByVal ManageYear As Integer, ByVal Machinetype As String) As DataSet
Dim ds As New DataSet
Dim aclsQuery As New clsDBSQLBased
Dim selectQuery As String


selectQuery = "select distinct cast(e.EquipmentId as varchar) + ' : ' + e.[description] [EquipmentName],e.EquipmentId [EquipmentID] from Eim_Equipment e,Eit_ManageEquipment m " + _
" where e.equipmentid=m.equipmentid and " & _
" m.ManageYear=" & ManageYear & _
" and e.MachineType='" & Machinetype & "'"
ds = aclsQuery.GetDataSet(selectQuery)
Return ds

End Function
-------------------------------------------------------------------------

The error is when i click submit button
after i was selected value from dropdown
and postback to server .
The selectedvalue is reset to the first data of dropdown(selectindex =0)
I try to search and debug code (and debug javascript).
Nothing wrong and now i don't know what to do if you can help me
It's very helpful.Thanks.

NC.
Mar 28 '07 #1
3 4295
nuchphasu
4 New Member
Hi
I am confuse about Ajax work. I have an javascript onchange event in dropdown that connect to server using Ajax.like this

Dropdown1 --> onchange( i clear Dropdown2,Dropdown3 and get data use Ajax to Dropdown2 )

Dropdown2 --> onchange ( i clear Dropdown3 and get data use Ajax to Dropdown3 )

After i select all Dropdown (1,2,3).
i click submit button that will save the data of dropdowns to database
when i click button the value of Dropdown2,Dropdown3 is disappear.
I think before back to server the onchange of Dropdown1 is working and clear data of Dropdown2,Dropdown3 .am i wrong? or this is a bug of Ajax?
Am i must save the data of dropdown to hidden textbox before send to server?

Someone pls explain me about Ajax's working.Thanks

NC.
Mar 29 '07 #2
acoder
16,027 Recognized Expert Moderator MVP
Post your code or provide a link so we can see the problem.
Mar 29 '07 #3
nuchphasu
4 New Member
Ok I use Ajax.dll from this site
http://ajax.schwarz-interactive.de/csharpsample/default.aspx
my code :
I have 2 dropdownlists.
1.ddlManageYear
2.ddlEquipmentID

ddlManageyear changed --> retrived data to ddlEquipmentID

[Javascript code in ATM.aspx] ________________________________

function ManageYear_onchange(machinetype)
{
//get selectedvalue from ddlManageyear
var iManageYear=document.forms[0].ddlManageYear.selectedIndex;
var vManageYear=document.forms[0].ddlManageYear[iManageYear].value;
clearDll("ddlEquipmentID");
if(iManageYear!=0)
{

AjaxFile.getEquipmentid(vManageYear, GetEquipmentRecords_CallBack);
}
else
{

document.getElementById("ddlEquipmentID").selected Index=0;
return
}

}
function clearDll(ddlname)
{
iLength=document.getElementById(ddlname).options.l ength;
for(i=0; i<iLength; i++)
{
document.getElementById(ddlname).options[0] = null;
}
document.getElementById(ddlname).options.add(new Option("--Please select--",0));

}

[Codebehind in ATM.aspx] ________________________________
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Ajax.Utility.RegisterTypeForAjax(GetType(AjaxFile) )
If Not Page.IsPostBack Then
loadDropDown() 'Retrieve data to ddlManageyear
ddlManageYear.SelectedValue = clsUtil.DateTimeNow.Year 'set ddlManageyear with default year
ddlManageYear.Attributes.Add("onchange", "ManageYear_onchange();")
Me.RegisterStartupScript("startup", "<script> ManageYear_onchange();</script>")
'when ddlManageYear changed ddlEquipmentID will retrieve data
End If
End Sub


[Code in AjaxFile.aspx ] ___________________________________
<Ajax.AjaxMethod()> _
Public Function getEquipmentid(ByVal ManageYear As Integer) As DataSet
.... retrieve data to ds ....
Return ds
End Function


Problem is that when ddlManageYear has changed ddlEquipmentid will retrieve data it's correct but when click submit button to save data
it don't have any data....
Please help
Mar 30 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Robin Bonin | last post by:
In my user contol I am creating a set of dropdownlists. Each list is created based on input from the other lists. The problem I am having is setting the selected index on the lists. If someone...
2
by: Chris | last post by:
I have a form that has several dropdownlists on it, and they have to be placed in 'If Not IsPostBack Then' becasue in some cases the choice of one effects the choices in another. The issue is that...
2
by: John Blair | last post by:
Hi, I have a dropdownlist in a grid header template - i have autopostback on but when i check the selectedindex in the page_load event (i have a routine which identifies the control that caused...
3
by: RFS666 | last post by:
Hello together, I tried to find out about populating an asp.net server control (a dropdownlist) from the clientside jscript, but I didn't find a solution up to now. I cannot use a html...
11
by: Santosh | last post by:
Dear all , i am writting following code. if(Page.IsPostBack==false) { try { BindSectionDropDownlist();
3
by: Lohboy | last post by:
Using ASP.NET and IE7. (Sorry if I am posting in the wrong forum but my problem seemed to be more related to the JavaScript side than the ASP.NET side.) I have two DropDownList controls the...
0
by: Med | last post by:
Hi, I have two dropDown lists ddlCars and ddlModels. ddlCars AutoPostBack="true" to populate the ddlModels when a car is selected. If the page is not valid (i.e. user left a mandatory textbox...
18
by: Redhairs | last post by:
Is it possible to get DropDownList.SelectedValue in Page_PreInit() event during the postback?
3
by: =?Utf-8?B?Y21lZWsxXzE5OTk=?= | last post by:
Hello, On a webpage, create an UpdatePanel with two DropDownLists. Set AutoPostBack of DropDownList1 to true. In the SelectedIndexChanged method, refill DropDownList2 and set the focus to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.