(1) 不要使用document.all.ID来访问页面上的元素,应该改用document.getElementById('ID')
Tip:
In VS2005, if you want to "replace document.all.ID." with "document.getElementById('ID')."
Then in the find input enter : document.all.{.*}.
in the replace input enter: document.getElementById('/1').
(2) Window.frames['frame_name'].location也不能使用,应该使用window.frame_name.location
javascript获取radio和checkbox的值的方法:
var element = document.getElementsByName('element_name');
var cnt = element.lenght;
var retValue = '';
for (var i = 0; i < cnt; i++)
{
if (element[i].checked)
{
retValue = element[i].value;
break;
}
}
// retValue is what we want.
javascript获取下拉框的值(value)和显示值(text)
var selectElement = document.getElementById('select_id');
var retValue = selectElement.value;
var retText = selectElement.options[selectElement.selectedIndex].text;
Ajax in asp.net
(1) include ajax.dll into the project.
(2) Register ajax class in the Page.onLoad(Of course, any other place before u use it)
Ajax.Utility.RegisterTypeForAjax(typeof(Class_Name));
(3) Declare Ajax method in c#
[Ajax.AjaxMethod()]
public string FunctionName(int id)
{
//.............
return 'hello';
}
(4) Call Ajax method in javascript
function ButtonOnClick()
{
Class_Name.FunctionName(id, FunctionName_CallBack);
}
(5) Define Callback function in javascript
function FunctionName_CallBack(response)
{
if (null != response.error)
{
// Error
}
else
{
// The value of response.value is 'hello'
}
}
------补充
(6) In Web.config Add:
<httpHandlers>
<add verb="POST,GET" path="ajax/*.ashx"
type="Ajax.PageHandlerFactory, Ajax" />
</httpHandlers>