.net跳转问题 怎么能不跳转页面调用一个页面让期代码执行比如http://localhost/sroweb/sroEvent/xunyou/xunyou.aspx调用这个页面但是不跳转到他还让页面里的sql语句注入了两个页面不在同一个虚拟目录下 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 string youraddr="xxx.aspx?yourdata="+xxxx;string outpage="<iframe width='0px' height='0px' style='display:none' src='" + youraddr+ "'/>");Response.Write(outpage); 如果需要打开新窗口:string youraddr="xxx.aspx?yourdata="+xxxx;string outpage="<javascript>window.open('"+ youraddr+ "');</javascript>");Response.Write(outpage); 把http://localhost/sroweb/sroEvent/xunyou/xunyou.aspx页面需要执行的代码,提炼到一个web server里 你的WinForm实现ICallbackEventHandler接口,有两个函数RaiseCallbackEvent和GetCallbackResult,分别用于接收客户端调用和向客户端发送数据。这个过程是不刷新页面的,类似AJAX,如下:public partial class Login : System.Web.UI.Page, ICallbackEventHandler { protected string returnValue; protected void Page_Load(object sender, EventArgs e) { string cbReference = ClientScript.GetCallbackEventReference(this, "val", "ReceiveServerData", "context"); string callbackScript = "function CallServer(val, context) { " + cbReference + ";}"; Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "CallServer", callbackScript, true); } public void RaiseCallbackEvent(string eventArgument) { if (eventArgument.StartsWith("cmd")) { returnValue = "NO"; string cmd = eventArgument.Split('|')[1]; if (cmd.Length > 4) { string id = cmd.Substring(0, 4); string password = cmd.Substring(4); DataSet ds = CGlobal.GetData( @"DECLARE @iPersonID AS int DECLARE @cPassword AS varchar(30) SET @iPersonID = CAST('" + id + @"' AS int) SET @cPassword = '" + password + @"' SELECT cName FROM tPerson WHERE iPersonID = @iPersonID AND cPassword = @cPassword SELECT MIN(dBeginDate), MAX(dEndDate) FROM tUnitPerson a JOIN tUnit b ON a.iUnitID = b.iUnitID WHERE a.iPersonID = @iPersonID AND a.bFinish = 0 AND b.dBeginDate <= GETDATE() AND DATEADD(DAY, 1, b.dEndDate) >= GETDATE() SELECT MIN(dBeginDate), MAX(dEndDate) FROM tUnitPerson a JOIN tUnit b ON a.iUnitID = b.iUnitID WHERE a.iPersonID = @iPersonID AND a.bFinish = 0"); if (ds == null) { returnValue = "数据库错误"; return; } if (ds.Tables[0].Rows.Count == 0) { returnValue = "错误的账号或密码"; return; } if (ds.Tables[1].Rows[0][0] == DBNull.Value) { if (ds.Tables[2].Rows[0][0] == DBNull.Value) { returnValue = "没有需要测评的项目"; } else { returnValue = "超过有效的测评期限: 测评日期从 " + ((DateTime)ds.Tables[2].Rows[0][0]).ToString("yyyy-MM-dd") + " 至 " + ((DateTime)ds.Tables[2].Rows[0][1]).ToString("yyyy-MM-dd"); } return; } Session["iPersonID"] = id; Session["cName"] = ds.Tables[0].Rows[0][0]; returnValue = "OK"; } } } public string GetCallbackResult() { return returnValue; } }IE端分别对应的是CallServer函数和ReceiveServerData函数<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="WebTest.Login" %><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <script language="javascript" type="text/javascript"> function login_onclick() { CallServer("cmd|" + document.getElementById("userID").value, ""); return false; } function ReceiveServerData(val) { if (val == "OK") location = "PersonUnit.aspx"; else alert(val); } </script> <style type="text/css"> .style1 { font-size: small; } .style2 { color: #0000FF; } .style3 { font-family: 仿宋_GB2312; } .style4 { font-size: small; font-family: 宋体, Arial, Helvetica, sans-serif; } .style5 { font-size: small; font-family: 仿宋_GB2312; } a { } </style></head><body oncontextmenu="self.event.returnValue=false;" onselectstart="return false;"> <form id="form1" runat="server"> <div style="width: 100%; height: 100%; text-align: center"> <table style="width: 1024px; height: 768px; vertical-align: top; background-image: url('PAGE.JPG');" cellspacing="0" cellpadding="0"> <tr style="height: 300px"> <td style="width: 320px"> </td> <td style="width: 110px"> </td> <td style="width: 73px"> </td> <td style="width: 521px"> </td> </tr> <tr style="height: 33px"> <td> </td> <td colspan="2" onclick="location='Proclamation.html';"> </td> <td> </td> </tr> <tr style="height: 60px"> <td colspan="4"> </td> </tr> <tr style="height: 33px"> <td> </td> <td colspan="2"> <input style="border: 0px none #FFFFFF; width: 183px; height: 33px; text-align: left; vertical-align: bottom; font-size: 18px;" id="userID" type="text" /><input style="display: none" id="rtn" type="text" /> </td> <td> </td> </tr> <tr style="height: 25px"> <td colspan="4"> </td> </tr> <tr style="height: 43px"> <td colspan="2"> </td> <td onclick="login_onclick();"> </td> <td> </td> </tr> <tr style="height: 274px"> <td colspan="4"> </td> </tr> </table> </div> </form></body></html> C# 里,封装一个函数,既把函数执行结果返回,又要返回部分内容,不用,REF还有它法不? C# .Net Winform窗体中用一个Combobox控件如何实现像百度搜索功能那样?请大家帮帮忙,谢谢! C# Opendialog 控件的用法 c#远程控制原理及实现 C#高手进来看看 DataView可否隐藏列??? 挑战高手权限!!! 请教,关于数据同步的问题.... 如何把这个VB转成C#? 关于一个UDP协议接收的循环问题! 问个entity framework 3.5的问题,急急急 如何在固定时间自动执行代码(比如每周日24:00)
string outpage="<iframe width='0px' height='0px' style='display:none' src='" + youraddr+ "'/>");
Response.Write(outpage);
string youraddr="xxx.aspx?yourdata="+xxxx;
string outpage="<javascript>window.open('"+ youraddr+ "');</javascript>");
Response.Write(outpage);
把http://localhost/sroweb/sroEvent/xunyou/xunyou.aspx页面需要执行的代码,提炼到一个web server里
{
protected string returnValue; protected void Page_Load(object sender, EventArgs e)
{
string cbReference = ClientScript.GetCallbackEventReference(this, "val", "ReceiveServerData", "context");
string callbackScript = "function CallServer(val, context) { " + cbReference + ";}"; Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "CallServer", callbackScript, true);
} public void RaiseCallbackEvent(string eventArgument)
{
if (eventArgument.StartsWith("cmd"))
{
returnValue = "NO"; string cmd = eventArgument.Split('|')[1]; if (cmd.Length > 4)
{
string id = cmd.Substring(0, 4);
string password = cmd.Substring(4); DataSet ds = CGlobal.GetData(
@"DECLARE @iPersonID AS int
DECLARE @cPassword AS varchar(30) SET @iPersonID = CAST('" + id + @"' AS int)
SET @cPassword = '" + password + @"' SELECT cName FROM tPerson WHERE iPersonID = @iPersonID AND cPassword = @cPassword SELECT MIN(dBeginDate), MAX(dEndDate)
FROM tUnitPerson a
JOIN tUnit b ON a.iUnitID = b.iUnitID
WHERE a.iPersonID = @iPersonID AND a.bFinish = 0 AND b.dBeginDate <= GETDATE() AND DATEADD(DAY, 1, b.dEndDate) >= GETDATE() SELECT MIN(dBeginDate), MAX(dEndDate)
FROM tUnitPerson a
JOIN tUnit b ON a.iUnitID = b.iUnitID
WHERE a.iPersonID = @iPersonID AND a.bFinish = 0"); if (ds == null)
{
returnValue = "数据库错误";
return;
} if (ds.Tables[0].Rows.Count == 0)
{
returnValue = "错误的账号或密码";
return;
} if (ds.Tables[1].Rows[0][0] == DBNull.Value)
{
if (ds.Tables[2].Rows[0][0] == DBNull.Value)
{
returnValue = "没有需要测评的项目";
}
else
{
returnValue = "超过有效的测评期限: 测评日期从 " + ((DateTime)ds.Tables[2].Rows[0][0]).ToString("yyyy-MM-dd") + " 至 " +
((DateTime)ds.Tables[2].Rows[0][1]).ToString("yyyy-MM-dd");
} return;
} Session["iPersonID"] = id;
Session["cName"] = ds.Tables[0].Rows[0][0]; returnValue = "OK";
}
}
} public string GetCallbackResult()
{
return returnValue;
}
}
IE端分别对应的是CallServer函数和ReceiveServerData函数<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="WebTest.Login" %><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script language="javascript" type="text/javascript">
function login_onclick() {
CallServer("cmd|" + document.getElementById("userID").value, "");
return false;
} function ReceiveServerData(val) {
if (val == "OK")
location = "PersonUnit.aspx";
else
alert(val);
}
</script>
<style type="text/css">
.style1
{
font-size: small;
}
.style2
{
color: #0000FF;
}
.style3
{
font-family: 仿宋_GB2312;
}
.style4
{
font-size: small;
font-family: 宋体, Arial, Helvetica, sans-serif;
}
.style5
{
font-size: small;
font-family: 仿宋_GB2312;
}
a
{
}
</style>
</head>
<body oncontextmenu="self.event.returnValue=false;" onselectstart="return false;">
<form id="form1" runat="server">
<div style="width: 100%; height: 100%; text-align: center">
<table style="width: 1024px; height: 768px; vertical-align: top; background-image: url('PAGE.JPG');"
cellspacing="0" cellpadding="0">
<tr style="height: 300px">
<td style="width: 320px">
</td>
<td style="width: 110px">
</td>
<td style="width: 73px">
</td>
<td style="width: 521px">
</td>
</tr>
<tr style="height: 33px">
<td>
</td>
<td colspan="2" onclick="location='Proclamation.html';">
</td>
<td>
</td>
</tr>
<tr style="height: 60px">
<td colspan="4">
</td>
</tr>
<tr style="height: 33px">
<td>
</td>
<td colspan="2">
<input style="border: 0px none #FFFFFF; width: 183px; height: 33px; text-align: left;
vertical-align: bottom; font-size: 18px;" id="userID" type="text" /><input style="display: none"
id="rtn" type="text" />
</td>
<td>
</td>
</tr>
<tr style="height: 25px">
<td colspan="4">
</td>
</tr>
<tr style="height: 43px">
<td colspan="2">
</td>
<td onclick="login_onclick();">
</td>
<td>
</td>
</tr>
<tr style="height: 274px">
<td colspan="4">
</td>
</tr>
</table>
</div>
</form>
</body>
</html>