javascript 链接
javascript前台后台实现链接
javascript 函数,可以放在一个外部的common.js文件中
引入:<script src="http://www.cnblogs.com/js/common.js" type="text/JavaScript"></script>
Code
function openwindow(url,name,iWidth,iHeight)
{
var iTop = (window.screen.availHeight-30-iHeight)/2; //获得窗口的垂直位置;
var iLeft = (window.screen.availWidth-10-iWidth)/2; //获得窗口的水平位置;
window.open(url,name,'height='+iHeight+',innerHeight='+iHeight+',width='+iWidth+',innerWidth='+iWidth+',top='+iTop+',left='+iLeft+',toolbar=no,menubar=no,status=no,scrollbars=no,resizable=no');
//window.open(url,name,'height='+iHeight+',width='+iWidth+',top='+iTop+',left='+iLeft+',toolbar=no,menubar=no,scrollbars=yes,resizeable=yes,location=no,status=yes');
}
function openwindowscroll(url,name,iWidth,iHeight)
{
var iTop = (window.screen.availHeight-30-iHeight)/2; //获得窗口的垂直位置;
var iLeft = (window.screen.availWidth-10-iWidth)/2; //获得窗口的水平位置;
window.open(url,name,'height='+iHeight+',innerHeight='+iHeight+',width='+iWidth+',innerWidth='+iWidth+',top='+iTop+',left='+iLeft+',toolbar=no,menubar=no,status=no,scrollbars=yes,resizable=yes');
//window.open(url,name,'height='+iHeight+',width='+iWidth+',top='+iTop+',left='+iLeft+',toolbar=no,menubar=no,scrollbars=yes,resizeable=yes,location=no,status=yes');
}
function ___doPostBack(eventTarget, eventArgument)
{
var theform = document.forms['form1'];
if (!theform)
{
theform = document.form1;
}
theform.__EVENTTARGET.value = eventTarget ;
theform.__EVENTARGUMENT.value = eventArgument;
theform.submit();
}
function openWindows(url, width, heigth)
{
var res=window.showModalDialog(url,window,"status:false;resizable:yes;dialogWidth:"+width+"px;dialogHeight:"+heigth+"px");
if(res=="pleasefresh")
{
refresh();
}
}
function openwindow(url,name,iWidth,iHeight)
{
var iTop = (window.screen.availHeight-30-iHeight)/2; //获得窗口的垂直位置;
var iLeft = (window.screen.availWidth-10-iWidth)/2; //获得窗口的水平位置;
window.open(url,name,'height='+iHeight+',innerHeight='+iHeight+',width='+iWidth+',innerWidth='+iWidth+',top='+iTop+',left='+iLeft+',toolbar=no,menubar=no,status=no,scrollbars=no,resizable=no');
//window.open(url,name,'height='+iHeight+',width='+iWidth+',top='+iTop+',left='+iLeft+',toolbar=no,menubar=no,scrollbars=yes,resizeable=yes,location=no,status=yes');
}
function openwindowscroll(url,name,iWidth,iHeight)
{
var iTop = (window.screen.availHeight-30-iHeight)/2; //获得窗口的垂直位置;
var iLeft = (window.screen.availWidth-10-iWidth)/2; //获得窗口的水平位置;
window.open(url,name,'height='+iHeight+',innerHeight='+iHeight+',width='+iWidth+',innerWidth='+iWidth+',top='+iTop+',left='+iLeft+',toolbar=no,menubar=no,status=no,scrollbars=yes,resizable=yes');
//window.open(url,name,'height='+iHeight+',width='+iWidth+',top='+iTop+',left='+iLeft+',toolbar=no,menubar=no,scrollbars=yes,resizeable=yes,location=no,status=yes');
}
function ___doPostBack(eventTarget, eventArgument)
{
var theform = document.forms['form1'];
if (!theform)
{
theform = document.form1;
}
theform.__EVENTTARGET.value = eventTarget ;
theform.__EVENTARGUMENT.value = eventArgument;
theform.submit();
}
function openWindows(url, width, heigth)
{
var res=window.showModalDialog(url,window,"status:false;resizable:yes;dialogWidth:"+width+"px;dialogHeight:"+heigth+"px");
if(res=="pleasefresh")
{
refresh();
}
}
Code
在前台调用该函数:
function OpenWindow()
{
var xn=document .getElementById ("ddlstXn");
var xq=document .getElementById ("ddlstXq");
var bh=document .getElementById ("txtBh");
if(xn.selectedIndex==0||xq.selectedIndex==0||bh.value.length==0)
{
alert ("请输入学年+学期+班号");
return false;
}
else
{
openwindow("CourseGradeRPT.aspx?xn="+xn.value+"&xq="+xq.value+"&bh="+bh.value+"", null ,900,600);
}
}
<asp:button CssClass="bt_query" text =" 综合查询" id="btnAllQueryGrade" runat="server" OnClientClick="OpenWindow();" />
--------------------------------------------------------------------------------------------------------------------------------------
在后台调用前台js函数:
function OpenWindowPrint(url)
{
openwindow(url ,null,800,600);
}
1.string url = "GradeQueryClassRPT.aspx?xn=" + this.hidXn.Value + "&xq=" + this.hidXq.Value + "&bh=" + this.hidBh.Value+"&kc="+Server.UrlEncode(this.ddlstCourseCode.SelectedItem.Text);
Page.ClientScript.RegisterStartupScript(this.GetType(), "", " <script type='text/JavaScript'>OpenWindowPrint('" + url + "'); </script>");
2.Response.Write(" <script type='text/JavaScript'>window.open('" + url + "'); </script>");//按钮会变样
3.Page.ClientScript.RegisterStartupScript(this.GetType(), "", " <script type='text/JavaScript'>window.open('" + url + "'); </script>");
在前台调用该函数:
function OpenWindow()
{
var xn=document .getElementById ("ddlstXn");
var xq=document .getElementById ("ddlstXq");
var bh=document .getElementById ("txtBh");
if(xn.selectedIndex==0||xq.selectedIndex==0||bh.value.length==0)
{
alert ("请输入学年+学期+班号");
return false;
}
else
{
openwindow("CourseGradeRPT.aspx?xn="+xn.value+"&xq="+xq.value+"&bh="+bh.value+"", null ,900,600);
}
}
<asp:button CssClass="bt_query" text =" 综合查询" id="btnAllQueryGrade" runat="server" OnClientClick="OpenWindow();" />
--------------------------------------------------------------------------------------------------------------------------------------
在后台调用前台js函数:
function OpenWindowPrint(url)
{
openwindow(url ,null,800,600);
}
1.string url = "GradeQueryClassRPT.aspx?xn=" + this.hidXn.Value + "&xq=" + this.hidXq.Value + "&bh=" + this.hidBh.Value+"&kc="+Server.UrlEncode(this.ddlstCourseCode.SelectedItem.Text);
Page.ClientScript.RegisterStartupScript(this.GetType(), "", " <script type='text/JavaScript'>OpenWindowPrint('" + url + "'); </script>");
2.Response.Write(" <script type='text/JavaScript'>window.open('" + url + "'); </script>");//按钮会变样
3.Page.ClientScript.RegisterStartupScript(this.GetType(), "", " <script type='text/JavaScript'>window.open('" + url + "'); </script>");
Code
string urllink = "GradeQueryClassRPT.aspx?xn=" + this.hidXn.Value + "&xq=" + this.hidXq.Value + "&bh=" + this.hidBh.Value;
string url=" <script type='text/JavaScript'>OpenWindowPrint('" + urllink + "'); </script> "
this.btnOpen.Attributes.Add("onclick", OnAddClientClick); //放在pageload里面
弹出模式对话框
/// <param name="page">要执行的页面对象</param>
/// <param name="URL">要打开的页面地址</param>
/// <param name="width">宽</param>
/// <param name="height">高</param>
public static string Fpage_f_win_opendialog_returnvalue(System.Web.UI.Page page, string URL, int width, int height)
{
string js2 = "javascript:";
js2 += string.Format("res=window.showModalDialog(\"{0}\",window,\"status:no;resizable:no;dialogWidth:{1}px;dialogHeight:{2}px\");", URL, width.ToString(), height.ToString());
js2 += "if (res==\"pleasefresh\")" + " {" + " refresh();" + "}";
//js2 += string.Format("res=window.showModalDialog(\"{0}\",window,\"status:false;resizable:yes;dialogWidth:{1}px;dialogHeight:{2}px\");", URL, width.ToString(), height.ToString());
return js2;
//page.RegisterClientScriptBlock("can", js2);
}
Onclick事件字符串
string OnAddClientClick = CommonPage.Fpage_f_win_opendialog_returnvalue(this.Page, "TeacherAdd.aspx", 850, 600);
//绑定新增按钮Onclick
this.btnAdd.Attributes.Add("onclick", OnAddClientClick);
string urllink = "GradeQueryClassRPT.aspx?xn=" + this.hidXn.Value + "&xq=" + this.hidXq.Value + "&bh=" + this.hidBh.Value;
string url=" <script type='text/JavaScript'>OpenWindowPrint('" + urllink + "'); </script> "
this.btnOpen.Attributes.Add("onclick", OnAddClientClick); //放在pageload里面
弹出模式对话框
/// <param name="page">要执行的页面对象</param>
/// <param name="URL">要打开的页面地址</param>
/// <param name="width">宽</param>
/// <param name="height">高</param>
public static string Fpage_f_win_opendialog_returnvalue(System.Web.UI.Page page, string URL, int width, int height)
{
string js2 = "javascript:";
js2 += string.Format("res=window.showModalDialog(\"{0}\",window,\"status:no;resizable:no;dialogWidth:{1}px;dialogHeight:{2}px\");", URL, width.ToString(), height.ToString());
js2 += "if (res==\"pleasefresh\")" + " {" + " refresh();" + "}";
//js2 += string.Format("res=window.showModalDialog(\"{0}\",window,\"status:false;resizable:yes;dialogWidth:{1}px;dialogHeight:{2}px\");", URL, width.ToString(), height.ToString());
return js2;
//page.RegisterClientScriptBlock("can", js2);
}
Onclick事件字符串
string OnAddClientClick = CommonPage.Fpage_f_win_opendialog_returnvalue(this.Page, "TeacherAdd.aspx", 850, 600);
//绑定新增按钮Onclick
this.btnAdd.Attributes.Add("onclick", OnAddClientClick);