运行环境vs2008
在前台js函数中设置控件获得焦点必须要加return语句,
function btn_Clear_Click() {
document.getElementById("txtOfficeID").value = "";
document.getElementById("txtEmployeeID").value = "";
document.getElementById("txtPassword").value = "";
document.getElementById("Label5").innerHTML = "";
document.getElementById("txtOfficeID").focus();
return false;
}
调用控件也要加return
<asp:button id="btn_Clear" style="Z-INDEX: 104; LEFT: 296px; POSITION: absolute; TOP: 429px;" tabIndex="5" runat="server" CssClass="btn_std" Width="96px" Text="clear" OnClientClick="return btn_Clear_Click()"></asp:button>
前台js中设置可以处理字符串消除前后空格
String.prototype.Trim = function() {
return this.replace(/(^/s*)|(/s*$)/g, "");
}
前台js函数:
function OpenJSSCAD() {
var OfficeName = document.getElementById("hfOfficeName").value;
var EmployeeName = document.getElementById("hfEmployeeName").value;
var m = screen.availHeight;
var h = screen.availWidth;
m = m - 40;
h = h - 10;
var feature = 'left=0,top=0,scrollbars=1,width= ' + h + ' ,height=' + m + ',resizable=yes,toolbar=no,addressbar=no,status=yes';
window.open('./Default.aspx?LoginOfficeName=' + OfficeName.Trim() + '&LoginEmployeeName=' + EmployeeName.Trim() + '', 'Default', feature).focus();
var w = window.open(' ', '_self');
w.opener = null;
w.close();
}
hfOfficeName和hfEmployeeName是2个前台隐藏控件
<asp:HiddenField ID="hfOfficeName" runat="server" />
<asp:HiddenField ID="hfEmployeeName" runat="server" />
后台调用前给隐藏控件赋值,
后台事件中调用前台js函数语句
this.hfEmployeeName.Value = EmployeeName;
this.hfOfficeName.Value = OfficeName;
Page.ClientScript.RegisterStartupScript(Page.GetType(), "", "<script language='javascript'>OpenJSSCAD();</script>");