Click here to Skip to main content
15,879,095 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I have a textBox in the index page and I want it to take the value from this text to the google search engine in another page.

how can i pass this variable from control to the cse?

This is the index code for passing the variable

HTML
Response.Redirect("Search.aspx?parma=" + TextBox1.Text);


and this is cse code

HTML
<script>
            (function () {
                var cx = '003646811200027851123:9ubv0q_x_z0';
                var gcse = document.createElement('script');
                gcse.type = 'text/javascript';
                gcse.async = true;
                gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
        '//www.google.com/cse/cse.js?cx=' + cx;
                var s = document.getElementsByTagName('script')[0];
                s.parentNode.insertBefore(gcse, s);
            })();
        </script>
        <gcse:search></gcse:search>
Posted
Updated 12-Dec-18 3:29am

Hello,

Please find below the code to do this.
HTML
<!DOCTYPE html>
<html>
<head>
<title>Element V2: Google-hosted Layout Demo</title>

<!-- Put the following javascript before the closing </head> tag. -->
<script>
  (function() {
    var cx = '003646811200027851123:9ubv0q_x_z0';
    var gcse = document.createElement('script'); gcse.type = 'text/javascript'; gcse.async = true;
    gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
        '//www.google.com/cse/cse.js?cx=' + cx;
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(gcse, s);
  })();
</script>
</head>

<body>
<div>
  Element V2 Google-hosted Layout Demo: open the results page in a new window
</div>

<!-- Place this tag where you want the search box to render -->
<!--
  1) newWindow=true overwrites settings stored in CSE control panel.
  2) Or store your settings in CSE control panel "Look and Feel" tab:
     Choose where your Google-hosted results appear: "New Window" or
     "Current Window".
 -->
<gcse:searchbox-only newWindow=true></gcse:searchbox-only>
</body>

</html>

Regards,
 
Share this answer
 
All I needed is this attribute

HTML
<gcse:search queryparametername="q" xmlns:gcse="#unknown"></gcse:search>
 
Share this answer
 
<script>
                  (function() {
                    var cx = 'CXXXXXXXXXXX';
                    var gcse = document.createElement('script');
                    gcse.type = 'text/javascript';
                    gcse.async = true;
                    gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
                        '//cse.google.com/cse.js?cx=' + cx;
                    var s = document.getElementsByTagName('script')[0];
                    s.parentNode.insertBefore(gcse, s);
                  })();
                  window.onload = function(){
                    document.getElementById('gsc-i-id1').value = '<?=$q?>';
                    $('.gsc-search-button').click();
                  };
                </script>
                <gcse:search></gcse:search>

<?=$q?>
is a php way to insert variables to javascript
 
Share this answer
 
v2
Comments
Richard Deeming 12-Dec-18 9:34am    
What does that have to do with an already-solved question about ASP.NET?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900