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

  • Home
  • SEARCH
  • 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 7610447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:25:12+00:00 2026-05-31T01:25:12+00:00

Using C# .NET 3.5 Framework here to make an .aspx web page. Anyways, the

  • 0

Using C# .NET 3.5 Framework here to make an .aspx web page. Anyways, the page accepts a GET variable x, and if supplied, I want the page to hook a JavaScript function foo(x) to the onload event of the page. The GET variable must be passed as an argument to foo.

I’m more familiar with other server-side scripting languages, and for example, in php I might do something like the following snippet, where I embed the php right into the <head> of the html page in the <script> (for simplicity I just set foo to the window.onload as I probably will only ever have one function set to this event anyways):

...

<script language="javascript" type="text/javascript">
function foo(x) {
    alert( x );
}

<?php

if( isset($_GET["x"]) )
    echo "window.onload = foo('" . $_GET["x"] . "');";
?>
</script>

...

Alternatively, I make the .js file a php parsed file that outputs the same and link that from the html file via src attribute of <script> (but I would still need a bit of embedded PHP to pass the GET variable to that script file src URL).

Anyways, with this aspx stuff, it looks a lot different, in that I have an underlying .cs file and there seems to be a huge strive to separate logic like this from the content of the page (.aspx) file. I wasn’t really sure how to get this same kind of behavior in this kind of environment.

It’s kind of not really ideal to have my JavaScript source inside my C# source as a string, etc.

Anyways, I did some searches on this but I can’t really find a clean solution. Anyone have a sensible solution for this type of thing in .aspx?

I should also point out that I do not want to rely on JavaScript to parse the window.location for the GET variables, as I use extensive path rewriting and I want to be flexible for POST variables.

UPDATE

Ok, so using the answers so far that are more focused on asp side of things I can mimic the php flavor as close as possible with something like this:

...
    <script language="javascript" type="text/javascript">

    function foo(x) {
        alert( x );
    }


    <%    
       String x = this.Request["x"];
       if(!String.IsNullOrEmpty(x))
           Response.Write( "window.onload = foo('" + Server.UrlDecode(x) + "');" );

    %>
</script>
...

Though this works, it’s not exactly the answer I am looking for. I was hoping for an aspx.cs solution that would divorce the need to embed this kind of code in my html file. Perhaps I was misleading when I gave the PHP example. I’d like to handle this on the .cs side of the world rather than embedding it directly in the html of the aspx file. Any ideas?

  • 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-05-31T01:25:13+00:00Added an answer on May 31, 2026 at 1:25 am

    I would define some global variables in your own script block and leave the main JS file alone.

    <script type="text/javascript">
    var foo = <% = yourVar %>
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using .Net framework 2.0 / jQuery to make an Ajax call to
I'm developing a small web application in ASP.Net (framework version 3.5) using VS2008 and
What is difference in developing applications using .Net Framework, Asp.net and developing application in
I am trying to leverage ORM given the following requirements: 1) Using .NET Framework
I wonder if is possible to use FTS with LINQ using .NET Framework 3.5.
We have an application written in C#, using .NET Framework 3.0 or 3.5 or
I am developing a Database File System . I am using - .Net framework
Using the .net framework you have the option to create temporary files with Path.GetTempFileName();
Using the .NET framework, I'm trying to replace double slash characters in a string
Using the .Net Framework 1.1, what options are available for monitoring threads from other

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.