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 7841595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:07:57+00:00 2026-06-02T16:07:57+00:00

I want to call a JavaScript function with HttpWebRequest or WebRequest in C#. I

  • 0

I want to call a JavaScript function with HttpWebRequest or WebRequest in C#. I don’t want to use a webbrowser which I can call invokemember.

Here is my code:

public void MyWebRequest(string url, string method, string data)
{  

       request = WebRequest.Create(url);

        if (method.Equals("GET") || method.Equals("POST"))
        {
            // Set the Method property of the request to POST.
            request.Method = method;
        }
        else
        {
            throw new Exception("Invalid Method Type");
        }
       string postData = data;

        byte[] byteArray = Encoding.UTF8.GetBytes(postData);

        request.ContentType = "application/x-www-form-urlencoded";

        request.ContentLength = byteArray.Length;

        dataStream = request.GetRequestStream();

        dataStream.Write(byteArray, 0, byteArray.Length);

        dataStream.Close();
}
MyWebRequest("http://example.com", "POST", "javascript:onclick=\"try(1,3)\"");

try is a JS function which has two int parameters. I want to call the onclick method, but how can I pass parameters to the function.

onclick="try(1,3);"
  • 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-02T16:07:59+00:00Added an answer on June 2, 2026 at 4:07 pm

    Just so this isn’t an open-ended question…

    WebRequest is essentially a “glorified” socket library that establishes a connection to and from a web server. It’s not more than a means to transfer data between a client (the app using the WebRequest) and the server hosting the site.

    For the same reason if you viewed the dataStream (referencing your code) you’d only see HTML markup and not actual layout elements and colors, styles, etc., javasript also won’t work. HTML needs a rendering agent, JavaScript needs an engine.

    So, if you need the ability to use JavaScript included on the page, WebBrowser is your best bet. It will load up any libraries/plugins necessary to run any JavaScript found on the page. It may be slower, yes, but that’s because it’s giving you a lot more than just transferring data (it’s also rendering HTML, executing any initialization scripts, and binding to any elements that the page has defined to be necessary for the aesthetics.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to call a JavaScript function through C#, using a WinForm's WebBrowser control.
I want to call the javascript function using mousehover jQuery event. Here is the
I want to call a javascript function from the code-behind file - but not
on (press) { here I want to call a javascript function } on (rollOver)
I have one javascript function. Which i want to call on hover of li
I want to use python to generate javascript code dynamiclly. def convert(jsstring=''): return 'function
I want to use fancybox from inside flash. I call a javascript function with
I want to call the JavaScript function (which internally shows a popup about the
I want to call a javascript function from my ASP.NET (C#) code, I want
I want to call a javascript function within a protected scope and i can

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.