前一段学习了下Ajax.dll和AjaxPro两个框架,发现了很多有意思的功能
其中为静态页面与.NET进行通讯提供一个绝好的模式,思路是通过.Net建立过程方法后由js进行访问,中间的通讯则用到了Ajax.dll框架
其中Ajax.dll在.Net下的配置请自行查阅
本例实现在HTML页面调用.Net方法直接提取MD5值
JS文件,用于读取.Net中的方法
其中为静态页面与.NET进行通讯提供一个绝好的模式,思路是通过.Net建立过程方法后由js进行访问,中间的通讯则用到了Ajax.dll框架
其中Ajax.dll在.Net下的配置请自行查阅
本例实现在HTML页面调用.Net方法直接提取MD5值
JS文件,用于读取.Net中的方法
//----------------------------------------------------------------
function GetMD5()
{
var pass=document.getElementById("TxtPass").value;
WebForm1.MD5(pass,StrMD5);
}
function StrMD5(res)
{
document.getElementById("PassMD5").value=res.value;
}
//-----------------------------------------------------------------
.Net下建立的获取MD5的方法function GetMD5()
{
var pass=document.getElementById("TxtPass").value;
WebForm1.MD5(pass,StrMD5);
}
function StrMD5(res)
{
document.getElementById("PassMD5").value=res.value;
}
//-----------------------------------------------------------------
<Ajax.AjaxMethod()> _
Public Function MD5(ByVal s As String) As String
Return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(s, "MD5").ToLower().Substring(8, 16)
End Function
直接调用Public Function MD5(ByVal s As String) As String
Return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(s, "MD5").ToLower().Substring(8, 16)
End Function
<html>
<head>
<title>Test</title>
<script language="javascript" src="ajax/common.ashx"></script>
<script language="javascript" src="ajax/ajaxTest_dll.WebForm1,ajaxTest_dll.ashx"></script>
<script language="javascript" src="ajaxTest.js"></script>
</head>
<body MS_POSITIONING="GridLayout">
<INPUT id="TxtPass" style="Z-INDEX: 101; LEFT: 64px; POSITION: absolute; TOP: 56px" type="text"
name="Text1"><INPUT id="PassMD5" style="Z-INDEX: 102; LEFT: 64px; POSITION: absolute; TOP: 80px" type="text"
name="Text2"><INPUT id="Button1" style="Z-INDEX: 103; LEFT: 224px; POSITION: absolute; TOP: 56px" type="button"
value="Button" name="Button1" onclick="GetMD5();"> <INPUT id="TxtTel" style="Z-INDEX: 104; LEFT: 64px; POSITION: absolute; TOP: 160px" type="text"
name="Text1">
</body>
</html>
<head>
<title>Test</title>
<script language="javascript" src="ajax/common.ashx"></script>
<script language="javascript" src="ajax/ajaxTest_dll.WebForm1,ajaxTest_dll.ashx"></script>
<script language="javascript" src="ajaxTest.js"></script>
</head>
<body MS_POSITIONING="GridLayout">
<INPUT id="TxtPass" style="Z-INDEX: 101; LEFT: 64px; POSITION: absolute; TOP: 56px" type="text"
name="Text1"><INPUT id="PassMD5" style="Z-INDEX: 102; LEFT: 64px; POSITION: absolute; TOP: 80px" type="text"
name="Text2"><INPUT id="Button1" style="Z-INDEX: 103; LEFT: 224px; POSITION: absolute; TOP: 56px" type="button"
value="Button" name="Button1" onclick="GetMD5();"> <INPUT id="TxtTel" style="Z-INDEX: 104; LEFT: 64px; POSITION: absolute; TOP: 160px" type="text"
name="Text1">
</body>
</html>