C#中向js中传递数据
请教一下,在C#中,在页面初始化的时候,我需要从数据库中查询出一批数据传递到js中,可以以拼串的方法实现,但是在C#中如何调用body中得onload事件,请各位大侠指教阿,拜托了,急
下面的是java中的一段代码,可以在jsp中直接调用该方法,但是C#中应该怎么调用得阿?
private static final String sJSHEAD = " <SCRIPT type=\ "text/JavaScript\ "> \n <!--\n ";
private static final String sJSEND = "\n//--> \n </SCRIPT> \n ";
public static String setAllJsArray2() {
BuKaSystemDBModel oBuKaSystemDBModel = new BuKaSystemDBModel();
// 从DB取出数据
DataBean oData = oBuKaSystemDBModel.getData();
if (oData == null)
return " ";
DataBean oBuData = (DataBean)oData.getDataBean(BuTableAccesser.sBU_TABLE_DATABEAN);
DataBean oKaData = (DataBean)oData.getDataBean(KaTableAccesser.sKA_TABLE_DATABEAN);
StringBuffer sRtnJsKa = new StringBuffer();
sRtnJsKa.append(sJSHEAD);
sRtnJsKa.append(sARRAYNAMEKA);
sRtnJsKa.append( " = new Array();\n ");
sRtnJsKa.append(sARRAYNAMEKA + "[0] = new Array();\n ");
sRtnJsKa.append(sARRAYNAMEKA + "[0][0] = new Option( ' ', ' ');\n ");
int iBuCount = 1;
for (int i=0;i <oBuData.getDataCount();i++) {
sRtnJsKa.append(sARRAYNAMEKA + "[ " + iBuCount + "] = new Array();\n ");
sRtnJsKa.append(sARRAYNAMEKA + "[ " + iBuCount + "][0] = new Option( ' ', ' ');\n ");
int iKaCount = 1;
for (int k=0;k <oKaData.getDataCount();k++){
if (oBuData.getString(sBU_BUCODE,i).equals(oKaData.getString(sKA_BUCODE,k))){
sRtnJsKa.append(sARRAYNAMEKA + "[ " + iBuCount + "][ " + iKaCount + "] = new ");
sRtnJsKa.append( " Option( ' " + oKaData.getString(sKA_KAMEISYO,k)+ " ', ' ");
sRtnJsKa.append(oKaData.getString(sKA_KACODE,k)+ " ');\n ");
iKaCount++;
}
}
iBuCount++;
}
sRtnJsKa.append(sJSEND);
return sRtnJsKa.toString();
}
基本上就是一个拼串导数据,然后在页面直接调用setAllJsArray2方法就可以了,
C#中如果拼完后是如何调用的??
------解决方案--------------------RegisterStartupScript
------解决方案--------------------Page.ClientScript.RegisterClientScriptBlock(GetType(), "XXX() ", statement())