473,574 Members | 2,726 Online
Bytes | Software Development & Data Engineering Community
+ 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_onch ange(machinetyp e)
{

var iManageYear=doc ument.forms[0].ddlManageYear. selectedIndex;
var vManageYear=doc ument.forms[0].ddlManageYear[iManageYear].value;
clearDll("ddlEq uipmentID");
clearDll("ddlVe ndor");
if(iManageYear! =0)
{
AjaxFile.getEqu ipmentid(vManag eYear,machinety pe, GetEquipmentRec ords_CallBack);
}
else
{
document.getEle mentById("ddlEq uipmentID").sel ectedIndex=0;
document.getEle mentById("ddlVe ndor").selected Index=0;
return
}

}

function GetEquipmentRec ords_CallBack(r esponse)
{
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.getEle mentById("ddlEq uipmentID").opt ions.add(new Option(ds.Table s[0].Rows[i]["EquipmentN ame"],ds.Tables[0].Rows[i]["EquipmentI D"]))
}
}
}

function clearDll(ddlnam e)
{
iLength=documen t.getElementByI d(ddlname).opti ons.length;
for(i=0; i<iLength; i++)
{
document.getEle mentById(ddlnam e).options[0] = null;
}
document.getEle mentById(ddlnam e).options.add( new Option("--Please select--",0));

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

-------------------------------------------------------------------------
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load
'Put user code to initialize the page here
Ajax.Utility.Re gisterTypeForAj ax(GetType(Ajax File))
If Not Me.IsPostBack Then
Me._MachineType = Request.QuerySt ring("MachineTy pe")
ddlManageYear.S electedValue = clsUtil.DateTim eNow.Year
ddlManageYear.A ttributes.Add(" onchange", "return ManageYear_onch ange('" & Me._MachineType & "');")
Me.RegisterStar tupScript("star tup", "<script> ManageYear_onch ange('" & Me._MachineType & "');</script>")
End If
End Sub
-------------------------------------------------------------------------

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

-------------------------------------------------------------------------
<Ajax.AjaxMetho d()> _
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.Equipmen tId as varchar) + ' : ' + e.[description] [EquipmentName],e.EquipmentId [EquipmentID] from Eim_Equipment e,Eit_ManageEqu ipment m " + _
" where e.equipmentid=m .equipmentid and " & _
" m.ManageYear=" & ManageYear & _
" and e.MachineType=' " & Machinetype & "'"
ds = aclsQuery.GetDa taSet(selectQue ry)
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(select index =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 4309
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,Dropd own3 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,Dropd own3 is disappear.
I think before back to server the onchange of Dropdown1 is working and clear data of Dropdown2,Dropd own3 .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.ddlEquipmentI D

ddlManageyear changed --> retrived data to ddlEquipmentID

[Javascript code in ATM.aspx] _______________ _______________ __

function ManageYear_onch ange(machinetyp e)
{
//get selectedvalue from ddlManageyear
var iManageYear=doc ument.forms[0].ddlManageYear. selectedIndex;
var vManageYear=doc ument.forms[0].ddlManageYear[iManageYear].value;
clearDll("ddlEq uipmentID");
if(iManageYear! =0)
{

AjaxFile.getEqu ipmentid(vManag eYear, GetEquipmentRec ords_CallBack);
}
else
{

document.getEle mentById("ddlEq uipmentID").sel ectedIndex=0;
return
}

}
function clearDll(ddlnam e)
{
iLength=documen t.getElementByI d(ddlname).opti ons.length;
for(i=0; i<iLength; i++)
{
document.getEle mentById(ddlnam e).options[0] = null;
}
document.getEle mentById(ddlnam e).options.add( new Option("--Please select--",0));

}

[Codebehind in ATM.aspx] _______________ _______________ __
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load
'Put user code to initialize the page here
Ajax.Utility.Re gisterTypeForAj ax(GetType(Ajax File))
If Not Page.IsPostBack Then
loadDropDown() 'Retrieve data to ddlManageyear
ddlManageYear.S electedValue = clsUtil.DateTim eNow.Year 'set ddlManageyear with default year
ddlManageYear.A ttributes.Add(" onchange", "ManageYear_onc hange();")
Me.RegisterStar tupScript("star tup", "<script> ManageYear_onch ange();</script>")
'when ddlManageYear changed ddlEquipmentID will retrieve data
End If
End Sub


[Code in AjaxFile.aspx ] _______________ _______________ _____
<Ajax.AjaxMetho d()> _
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
6999
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 changes box1, I want to set the selected index in box2 = 0. When I do this, I dont get an error, but when the page loads, it still has the selected...
2
1177
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 if IU allow a user to add (via a pop-up modal form) a new item for that particular dropdwonlist, once they save there new value and return to the...
2
4650
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 the postback and it determines the dropdownlist correctly) it is always 0 - i am NOT rebinding to the dropdownlist in the page_load event i.e. only...
3
2626
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 dropdownlist, because a database query in codebehind has to be done, when a new listItem is selected. So, I need to use a servercontrol dropdownlist. ...
11
5794
by: Santosh | last post by:
Dear all , i am writting following code. if(Page.IsPostBack==false) { try { BindSectionDropDownlist();
3
10567
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 second of which resides within an UpdatePanel control which responds to a change in the first DropDownList. I also have a hidden button nested inside the...
0
3515
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 blank and presented by ValidatorCalloutExtender message when attempting to submit), selecting an item in ddlCars DOES NOT postback the first time,...
18
5418
by: Redhairs | last post by:
Is it possible to get DropDownList.SelectedValue in Page_PreInit() event during the postback?
3
3825
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 DropDownList1 using the ScriptManager SetFocus method. Use the Visual Studio debugger. Set a breakpoint on in the (!IsPostBack) part of the PageLoad...
0
7832
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8093
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7843
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8129
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5331
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3768
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2262
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1364
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1094
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.