我可以用request.form["ID"]来得到javascript中的testbox和其他控件的值。但是我现在在javascript中用一个google共享的控件,如下
<body>
    <form id="form1" runat="server">
    <div id="searchcontrol">Loading...</div>
    </form>
</body>searchcontrol是在javascript中定义的一个类,如下
var searchControl = new google.search.SearchControl();
这个类里有一个文本框和一个查询按钮,但是我用他的id去找这个控件,他返回的却是空,那说明没有找到这个控件。我现在奇怪的是,用request.form["ID"]可以找到textbox但为什么找不到这个google的控件。他现在可以在网页上正常显示和搜索。

解决方案 »

  1.   

    不清楚。你可以试一试在javascipt的onclick或者什么的里面是不是可以取道值。如果可以的话,实在不行就创建两个因此的textbox 服务器端控件,在javascript中给它们赋值,再在aspx中取值
      

  2.   

    服务器控件在客户段使用的时候 如:getElementById("<%=txtName.ClientID%>")
      

  3.   

    最好多提供些代码出来,,,按你目前提供的代码,,说明不了什么问题,,,但是有一个,,,<div id="searchcontrol">Loading... </div>真的还没有试过用request.from["searchcontrol"]取到div的值啊要取div里的内容用javascript的innerHTML吧
      

  4.   

    js执行是不是在那个控件加载完了 查找的  你在onload里查找看能不能找到
      

  5.   

    这个是google的原程序,但是那个key需要注册,大家看看代码。onload里的SearchControl应该是一个类。google.load("search", "1");应该是加载了那个类的包。这一句searchControl.draw(document.getElementById("searchcontrol"));好像是要通过ID得到那个类。但是我在c#里用Request["ID"]能够得到TextBox1或者ListBox1,并得到TextBox1和ListBox1的值。可是用searchcontrol这个ID得不到searchControl这个类
    =======================================================================================================================<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="SynSearch._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>My Google AJAX Search API Application</title>
        <script src="http://www.google.com/jsapi?key=ABQIAAAA8tCc3YHvzref7QrlUtLBJxTBJaQEFP-mki-GESoXGMdJEk8LRhQpQtwvOJG0eFfTfF75a80qoXZ29Q" type="text/javascript"></script>
        <script language="Javascript" type="text/javascript">
        //<![CDATA[    google.load("search", "1");    function OnLoad() {
          // Create a search control
          var searchControl = new google.search.SearchControl();      // Add in a full set of searchers
          searchControl.addSearcher(new google.search.WebSearch());      // Tell the searcher to draw itself and tell it where to attach
          searchControl.draw(document.getElementById("searchcontrol"));      // Execute an inital search
          searchControl.execute("Google");
        }
        google.setOnLoadCallback(OnLoad);    //]]>
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div id="searchcontrol">Loading...</div>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:ListBox ID="ListBox1" runat="server" Width="241px"></asp:ListBox>
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
        </form>
    </body>
    </html>
      

  6.   

    还有谁知道<div>是什么?不过那个类searchcontrol是在javascript中定义的,但是textbox1和listbox1是在<body>里定义的。是不是因为这个才取不到?看来在body里的<div id="searchcontrol">Loading...</div>是调用javascript里的searchcontrol类,但是为什么在c#里用这个ID取不到这个类呢?
      

  7.   

    你添加这个js方法需要从google买吗?直接加了可以用吗?这个文件里面都哪些方法呀?
      

  8.   

    注册以后得到一个key,把我贴的代码里的key替换了,保存到一个html文件里双击就可以了。我把这个文件放到了c#页面的资源文件里,但是引用不了那个文本框。我想得到搜索字符,然后换成我自己的搜索文字。