Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8288813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:21:24+00:00 2026-06-08T12:21:24+00:00

I have a java script variable and I want to use it into my

  • 0

I have a java script variable and I want to use it into my sqldatasourse how can I do this. Here is my java script code

var div = document.getElementById('main_content').offsetHeight;
            var length = Mah.round(div / 400);

And I want to use variable length here in select command

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:qbuyConnectionString1 %>" 
         SelectCommand="SELECT TOP variable * FROM [advertisement] WHERE ([enable] = @enable) ORDER BY NEWID()">
        <SelectParameters><asp:Parameter DefaultValue="1" Name="enable" Type="Int32" /></SelectParameters>
</asp:SqlDataSource>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T12:21:26+00:00Added an answer on June 8, 2026 at 12:21 pm

    The easiest solution based on how you are trying to do this is a combination of some of the aforementioned suggestions.

    1. Create a server-side ASP.NET hidden field control in your page.
    2. Set the server-side hidden field control to the JavaScript variable value.
    3. In the _Selecting event which fires prior to the database being accessed, set the ‘Parameter’ value to that of the hidden server-side control.

    Step 1:

    <!--Create an ASP.NET hidden field server control-->
    <asp:HiddenField ID="HiddenField1" runat="server" />
    

    Step 2:

    //JavaScript you were using populating the 'length' variable:
    var div = document.getElementById('main_content').offsetHeight;
    var length = Mah.round(div / 400);
    //Now set the hidden field's value to your JS variable value:
    document.getElementById('<%= HiddenField1.ClientId %>');
    

    Step 3:

    protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
    {
        //The 'Selecting' event fires *prior* to the wired up Select method being called.
        //This is the spot to add in or modify any of the parameter values:
        e.Command.Parameters["LengthParameter"].Value = this.HiddenField1.Value;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have javascript string variable with var sttr=We prefer questions that can be answered
So I have a xml document loaded in JavaScript variable. Xml looks like this:
I have a script which loads content into a iframe using: document.GetElementById('iframeid').src = 'site.html';
I have a JavaScript variable that stores a websocket connection like so: var ws
I have a JavaScript file which has a variable as such: var ads =
Can you setup a variable for javascript in one page and have another page
I have a table with variable-width cells, and I want to give the browser
Here's the situation: I have a variable number of dynamically created update panels on
My iframe has a variable. I want to access document holding the iframe and
I want to make a for example content variable in javascript which will have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.