后台代码(把public改成protected也可以)
public string ss(string aa)
{
return(aa);
}
2、在html里用<%=fucntion()%>可以调用
前台脚本
<script language=javascript>
var a = "<%=ss()%>";
alert(a);
</script>这个方法带参数怎么样才行捏??
public string ss(string aa)
{
return(aa);
}
2、在html里用<%=fucntion()%>可以调用
前台脚本
<script language=javascript>
var a = "<%=ss()%>";
alert(a);
</script>这个方法带参数怎么样才行捏??
BJProduct Product = new BJProduct();
BJInfo Info = new BJInfo();
protected string Title;
protected string Pic1 = string.Empty;
protected string Content = string.Empty;
protected void Page_Load(object sender, EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(GetType());
}
[AjaxPro.AjaxMethod]
public string ResurnContent(string pic)
{
BJProduct Product = new BJProduct();
Product.PictureUrl = pic;
WebManager.GetInfo(Product, "&pictureurl="); return Server.HtmlDecode(Product.Content).ToString();
}
</script>function ChangeImg(obj)
{
var img1=document.getElementById('img1');
img1.src=obj;
ASP.hcbz_aspx.ResurnContent(obj,callback)
}
function callback(res)
{
if(res!=null)
{
document.getElementById('div1').innerHTML=res.value;
}
}
function ShowPic()
{
document.getElementById('img1').src='<%=Pic1 %>';
ASP.hcbz_aspx.ResurnContent('<%=Pic1 %>',callback)
}
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class Ajax_Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
public string str(string aa)
{
return aa;
}
}<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Ajax_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
<script type="text/javascript">
function ShowInfo()
{
var res='<%=str("aa") %>';
alert(res);
}
</script>
</head>
<body onload="ShowInfo();">
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
个人不建议使用ajax框架,要用也用jquery这种js框架比较好
{
return str;function Init()
{
var v = "";
var s = '<%=ss("'+v+'") %>';
alert(s);
}
{
return str;
}
function Init()
{
var v = "";
var s = '<%=ss("'+v+'") %>';
alert(s);
}
jquery用都没用过Ajax只是验证的时候使用比较多再问下4楼MM onload="ShowInfo(‘aa’);“这样传过去参数的话
function ShowInfo(objaa)
{
var res='<%=str(‘+objaa+’) %>';
alert(res);
}
是不是这样的???
因为浏览该网页的时候是先执行<%=ss()%>然后才执行HTML内容(包括JS)
所以如果你想把JS的参数传给ss()函数是不可能的
不知道楼主具体是什么需求,详细解释后再作打算
建议还是用ajaxpro好些
感谢MM的大力支持。。结贴后再派分。。
我的意图跟10楼的帅哥说的那样。。
不知道JS有办法实现没?
function go()
{
document.getElementById("Button2").click();
}
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="go();return false;" />
<asp:Button ID="Button2" runat="server" Text="Button" OnClick="Button2_Click" Style="display: none;" />
protected void Button2_Click(object sender, EventArgs e)
{
this.ss("1");
}
private void ss(string ss)
{
this.TextBox1.Text = ss;
}
谢谢15楼帅哥意见。。ajax的学习有什么好的意见没??还有jQuery技术好像也很不错以后还是要混WEB这行的。。大家给条明路吧
这是页面输出时在服务器端动态执行的
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Ajax_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
<script type="text/javascript">
function ShowInfo()
{
var res='<%=str("aa") %>';
alert(res);
}
</script>
</head>
<body onload="ShowInfo();">
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>