我查看了许多文章,都没具体讲到javascript和C#的互相交互使用.也就是说在javascript代码里可以调用C#内容,在C#代码里可以调用javascript代码.
例如:我如何把C#里的变量放到javascript代码里处理;把javascript里的变量放到c#代码里处理;当我用javascript在客户端处理完数据后,如何把结果传到服务器端.
请各位大虾帮忙!!!本人是第一次发贴,谢谢!!

解决方案 »

  1.   

    首先,你要清楚c# 是在服务器允许,js在客户端运行,
      

  2.   

    如何把C#里的变量放到javascript代码里处理string x="c#"'
    Response.Write("<script>alert('"+x+"')</script>");把javascript里的变量放到c#代码里处理var x="javascript";
    window.location.href="ok.aspx?id="+x或者提交,或者用xmlhttp,等等
      

  3.   

    Javascript读CodeBehind变量
    ---- .cs 中 ---- 
    public class xxx 
    public string jsValue ; 
    public page_onload(){ 
    jsValue = "你想要的值"; 

    .... ---- .aspx 中 ------ alert("<%=jsValues%>");
      

  4.   

    CodeBehind读客户端控件值string a = Request.Form["ControlName"].ToString();
      

  5.   

    如何把javascript里的变量放到c#代码里处理;
    当我用javascript在客户端处理完数据后,如何把结果传到服务器端这是同一个问题吧javascript传变量到codebehind没有直接的办法。方法一是孟子所说:
    var x="javascript";
    window.location.href="ok.aspx?id="+x方法二是孟子所说:提交,具体参考孟子的文章:
    http://dotnet.aspx.cc/ShowDetail.aspx?id=0C25068E-55EA-4124-8CD6-726ECF5D5D3B方法三是孟子所说:用xmlhttp,具体参考孟子的网站 http://dotnet.aspx.cc方法四如下:
    回复人: upto(阿球) ( ) 信誉:104  2004-03-07 19:10:00  得分:0  
     
      <input class="Button" id="Back" type="button" value="返回文件管理器" runat="server" onserverclick="Back_ServerClick" NAME="Back">
    protected void Back_ServerClick(object sender, EventArgs e)
    {
    if (folderPath != null && folderPath != "/")
    Response.Redirect("BrowseFiles.aspx?Folder=" + folderPath);
    else
    Response.Redirect("BrowseFiles.aspx");

      

  6.   

    我还是不太清楚你们说的意思。
    C#是服务器语言,在服务端执行,而js是客户端语言,在客户端执行.
    我现在困惑的是:我在客户端要从客户端的数据,然后我在js中对它们处理,然后又可以把结果送到服务器端处理.也就是说:js中可以读取用户输入的信息,然后处理,处理后传到服务器再处理,然后又把结果送回客户端的js中.
    其中:<1>把结果送到客户端的js中可以用<%=C#变量%>解决.
         <2>处理的结果传到服务器可以用xxx.aspx?js变量解决.
         <3>从用户输入控件读取数据,把输入的数值放到js中处理.
    我之所以提问:就是因为我在aspx中的DataGrid中有一行删除按纽,当我按"删除"后,我希望弹出对话框,提示用户是否真是要删除.如果不想删除可以"取消".
    问题是:我不能"取消".我就想这样解决:在C#中有onclick();在这function中我放了response.write("if confirm(要删除吗?)" delete(C#code)),也就是说我想在js中调用C# function.
      

  7.   

    <script language="vb" runat="server">
      ...
       
      Sub dgPopularFAQs_ItemDataBound(sender as Object, e as DataGridItemEventArgs)
        ' First, make sure we're NOT dealing with a Header or Footer row
        If e.Item.ItemType <> ListItemType.Header AND _
             e.Item.ItemType <> ListItemType.Footer then
          'Now, reference the LinkButton control that the Delete ButtonColumn 
          'has been rendered to
          Dim deleteButton as LinkButton = e.Item.Cells(0).Controls(0)      'We can now add the onclick event handler
          deleteButton.Attributes("onclick") = "javascript:return " & _
                     "confirm('Are you sure you want to delete FAQ #" & _
                     DataBinder.Eval(e.Item.DataItem, "FAQID") & "?')"    
        End If
      End Sub
    </script><form runat="server">
      <asp:datagrid id="dgPopularFAQs" runat="server"
          ...
          OnItemDataBound="dgPopularFAQs_ItemDataBound">

          ...
      </asp:datagrid>
    </form> 
      

  8.   

    谢谢你们:下面的看不太懂,特别是Eval() deleteButton.Attributes("onclick") = "javascript:return " & _
                     "confirm('Are you sure you want to delete FAQ #" & _
                     DataBinder.Eval(e.Item.DataItem, "FAQID") & "?')"    
      

  9.   

    deleteButton.Attributes("onclick") = "javascript:return " & _
                     "confirm('Are you sure you want to delete FAQ #" & _
                     DataBinder.Eval(e.Item.DataItem, "FAQID") & "?')"   看不懂,请大家指教!!!!
      

  10.   

    Server->Custom
    <button id=button1 onclick=getserverdate('<%服务器段函数%>')>
    <script language=Javascript>function getserverdate(var1) {alert(var1)}</script>Custom->Server
    提交了
      

  11.   

    confirm('Are you sure you want to delete FAQ #" & _
                     DataBinder.Eval(e.Item.DataItem, "FAQID") & "?')"  
    这句话什么意思? 请详细解释!!!!
      

  12.   

    confirm('Are you sure you want to delete FAQ #" & _
                     DataBinder.Eval(e.Item.DataItem, "FAQID") & "?')"  
    这句话什么意思? 请详细解释!!!!