后台代码(把public改成protected也可以)
           public string ss(string aa)
           {
              return(aa);
           }
        2、在html里用<%=fucntion()%>可以调用
           前台脚本
           <script language=javascript>
           var a = "<%=ss()%>";
           alert(a);
           </script>这个方法带参数怎么样才行捏??

解决方案 »

  1.   

    不要跟我说Ajax。。不会那玩意啊
      

  2.   

    <script runat="server">
        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)
    }
      

  3.   

    不用ajax
    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>
      

  4.   

    不用ajax不行的,用你这种方法时,实际上是因为后台已经编译好了,前台调用的,但是因为程序先解析后台,再解析前台,所以无法取的你的参数,唯一的办法就是Ajax,这个也是做web开发必学的,学两天你就知道了,比较简单
    个人不建议使用ajax框架,要用也用jquery这种js框架比较好
      

  5.   

     protected string ss(string str)
    {
       
       return str;function Init()
     {
       var v = "";
       var s = '<%=ss("'+v+'") %>';
       alert(s);
     }
      

  6.   

     protected string ss(string str)
    {
       
       return str;
    }
    function Init()
     {
       var v = "";
       var s = '<%=ss("'+v+'") %>';
       alert(s);
     }
      

  7.   

    感谢4楼MM的大力支持同时也谢谢6楼帅哥的宝贵意见
    jquery用都没用过Ajax只是验证的时候使用比较多再问下4楼MM   onload="ShowInfo(‘aa’);“这样传过去参数的话
     function ShowInfo(objaa)
        {
          var res='<%=str(‘+objaa+’) %>';
          alert(res);
        }
    是不是这样的???
      

  8.   

    楼主这个传参是没有意义的
    因为浏览该网页的时候是先执行<%=ss()%>然后才执行HTML内容(包括JS)
    所以如果你想把JS的参数传给ss()函数是不可能的
    不知道楼主具体是什么需求,详细解释后再作打算
      

  9.   

    5楼的代码测试通过了的
    建议还是用ajaxpro好些
      

  10.   


    感谢MM的大力支持。。结贴后再派分。。
    我的意图跟10楼的帅哥说的那样。。
    不知道JS有办法实现没?
      

  11.   

    也可
    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;
    }
      

  12.   

    不会的话可以学习啊,很简单的,再说多学了一个东西不是很好嘛?用AJAX来做这个肯定是很方便的。
      

  13.   


    谢谢15楼帅哥意见。。ajax的学习有什么好的意见没??还有jQuery技术好像也很不错以后还是要混WEB这行的。。大家给条明路吧
      

  14.   

    LZ <%=ss()%>这个不是js的代码
    这是页面输出时在服务器端动态执行的
      

  15.   

    HTML code
    <%@ 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>