1

Is there a way to use c# to run a java script function on a website?

My code is below, basically at the moment it logs in by using a post form.

Click here for code

After it logs in i need it to run a java script function which is 'javascript:voteTab()';.

Thanks for your help guys.

3 Answers 3

1

Sure, do something like this in your code behind:

ClientScript.RegisterClientScriptBlock(this.GetType(), "key", "voteTab();", true);
Sign up to request clarification or add additional context in comments.

4 Comments

I get this error when using that code. Error 2 The name 'ClientScript' does not exist in the current context C:\Users\oliver\documents\visual studio 2010\Projects\VoteBot\VoteBot\Votifier.cs 53
is there a c# solution for this? Thats sort of what im aiming for
You mean not from a page? Guess so, but it will take a whole lot of work and the javascript do need to be run in a browser.
Im making a bot like thing where it automatically logs in and runs a javascript code, it pretty much votes automatically on a website. And yeah, its a client :)
1

you can run javascript with this in code behind,

ClientScript.RegisterStartupScript(typeof(Page), "key", "<script>voteTab();</script>");

EDIT:

using System.Web.UI; // for Page
using System.Web; //for HttpContext

Page page = HttpContext.Current.CurrentHandler as Page;
page.ClientScript.RegisterStartupScript(typeof(Page), "key", "<script>voteTab();</script>");

2 Comments

@sinakyazici I get this error when using that code. Error 2 The name 'ClientScript' does not exist in the current context C:\Users\oliver\documents\visual studio 2010\Projects\VoteBot\VoteBot\Votifier.cs 53
Im sorry , it still doesnt work. Bear in mind that im using c# not asp.net. Im getting red lines under Page and HttpContext saying they dont exist.
1

I think you are trying to automate a website, rather than author one? You might want to take a look at Selenium which is a tool for automating websites.

As you are looking for a code solution I will also mention that selenium has .NET bindings.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.