SimpleSearch.ascx中:
--------------------------------------------------------------------------
<SCRIPT language="JavaScript">
function checkall(){
list=document.Form1
if ((list.DropDownList1.options[list.DropDownList1.selectedIndex].value=="0000" ||......)
{window.alert("地点、职能必须选择!")
return false
}
.......省略
}
</SCRIPT><asp:imagebutton id="ImageButton1" runat="server" ImageUrl="../images/searchimg.gif"></asp:imagebutton>-----------------------------------------------------------------------------
SimpleSearch.ascx.Cs中:然后我在SimpleSearch.ascx.Cs中为ImageButton1加了ImageButton1.Attributes["onclick"]="javascript:return checkall();";然后我把这个SimpleSearch.ascx用户控件拖到index.aspx页面内,可是实际一运行index.aspx,发现SimpleSearch.ascx控件中的javascritpt 却根本不起作用,不知道为什么,
可是同样的做法,我如果不做成控件,直接做成aspx,aspx.cs 时却没问题。
--------------------------------------------------------------------------
<SCRIPT language="JavaScript">
function checkall(){
list=document.Form1
if ((list.DropDownList1.options[list.DropDownList1.selectedIndex].value=="0000" ||......)
{window.alert("地点、职能必须选择!")
return false
}
.......省略
}
</SCRIPT><asp:imagebutton id="ImageButton1" runat="server" ImageUrl="../images/searchimg.gif"></asp:imagebutton>-----------------------------------------------------------------------------
SimpleSearch.ascx.Cs中:然后我在SimpleSearch.ascx.Cs中为ImageButton1加了ImageButton1.Attributes["onclick"]="javascript:return checkall();";然后我把这个SimpleSearch.ascx用户控件拖到index.aspx页面内,可是实际一运行index.aspx,发现SimpleSearch.ascx控件中的javascritpt 却根本不起作用,不知道为什么,
可是同样的做法,我如果不做成控件,直接做成aspx,aspx.cs 时却没问题。
注意双引号改单引号。
如:Response.write ("<Script language='javascript'>")
.....
....Response.write ("</script>")
' //打印javascript程序,此段程序响应客户端的事件
Dim strScript As String = ""
strScript += "<script language='javascript'> " & ControlChars.CrLf
strScript += "function do_gopage(strgopage)" & ControlChars.CrLf & "{" & ControlChars.CrLf
........(此处省略若干行。。)
Response.Write(strScript)
strScript += "<script language='javascript'> " & ControlChars.CrLf
strScript += "function do_gopage(strgopage)" & ControlChars.CrLf & "{" & ControlChars.CrLf
strScript += "document.all('" + ID + "_hid_GoPage').value = strgopage;" & ControlChars.CrLf(上面的语句组合控件新生成的ID,ID是根据规律自动生成。) strScript += "document.all('" + ID + "_hid_CustomClicked').value = true;" & ControlChars.CrLf
strScript += "document.all('" + ID + "_hid_GoPage').form.submit();" & ControlChars.CrLf & "}" & ControlChars.CrLf
strScript += "function f_Submit()" & ControlChars.CrLf & "{" & ControlChars.CrLf
strScript += "var int_GoPage = document.all('txt_GoPage').value;" & ControlChars.CrLf
你的方法看不懂啊
function checkall(){
list=document.Form1
if ((list.SimpleSearch1_DropDownList1.options[list.SimpleSearch1_DropDownList1.selectedIndex].value=="0000" || list.SimpleSearch1_Function.options[list.SimpleSearch1_Function.selectedIndex].value=="0000") && (list.SimpleSearch1_keyword.value=="" || list.SimpleSearch1_keyword.value=="输入公司/职位关键字"))
{window.alert("地点、职能必须选择!")
return false
}
if ((list.SimpleSearch1_DropDownList1.options[list.SimpleSearch1_DropDownList1.selectedIndex].value=="0000")&&(list.SimpleSearch1_SubFunction.options[list.SimpleSearch1_SubFunction.selectedIndex].value=="0000")&&(list.SimpleSearch1_keyword.value==""))
{window.alert("关键字不能为空!")
return false
}
else return true
}
function clearfield(){
if (document.Form1.SimpleSearch1_keyword.value == "输入公司/职位关键字")
document.Form1.SimpleSearch1_keyword.value = "";
}
function GetObjID(ObjName)
{ for (var ObjID=0; ObjID < document.Form1.elements.length; ObjID++)
if ( document.Form1.elements[ObjID].name == ObjName )
{ return(ObjID);
break;
}
return(-1);
}function ChangeOption(ObjName, DesName)
{
//GET OBJECT VALUE, ID OF DESTINATION OBJECT
ObjID = GetObjID(ObjName);
DesObjID = GetObjID(DesName);
if ( ObjID != -1 && DesObjID != -1 )
{
CatValue = document.Form1.elements[ObjID].value.substring(0, 2);
if ( CatValue == "0" )
document.Form1.elements[DesObjID].length=0;
else
{ //PARSING
document.Form1.elements[DesObjID].length=0;
var tt = document.Form1.FuncCode.value;
var SubCategory = tt.split(";");
//GENERATE OPTIONS
document.Form1.elements[DesObjID].options[0]= new Option("---所有---", "0000");
j=1;
for (var i=0; i< SubCategory.length; i++ )
{
pp = SubCategory[i].split(",");
if ( pp[0].substring(0,2) == CatValue && pp[0].substring(2,4) != "00" )
{
document.Form1.elements[DesObjID].options[j]= new Option( pp[1], pp[0]);
j++;
}//if
}//for
}//if
}//if
}
</SCRIPT>这样一大堆,要如何改你那样的啊?!
可以配合这个写javascript
既在javascript内用<%xxx%>输出该id可以保证后来得到的javascript正确
或者
在后台cs中拼接出你的javascript
然后
RegisterStartupScript
或者
RegisterClientScriptBlock
你的javascript