0

I am using the below client script in aspx code behind to call a javascript function. But the below client script in public static method so i got the error in registerstartupscript first argument.My older post is here Call non-static function from static function

If any one have a possible solutions please post..

Page.ClientScript.RegisterStartupScript(typeof(Page), "SymbolError", "from_bill_tab();");

7
  • Are you trying to register a startup javascript in a [WebMethod] ? Commented Feb 21, 2013 at 4:54
  • No can u tell me that.. Commented Feb 21, 2013 at 4:57
  • I'm just looking at the other post you linked to, and it looks like your trying to do it in a [WebMethod] Commented Feb 21, 2013 at 4:58
  • yes [WebMethod] only allow the public static method. Am i right?. Thats why i need this type of client script to call a js function Commented Feb 21, 2013 at 5:10
  • I don't think you can do this (register a script) from a static WebMethod in an aspx page. Is your intent to call your WebMethod from the aspx page via javascript/ajax? Commented Feb 21, 2013 at 5:21

2 Answers 2

0

Try this:

ClientScript.RegisterStartupScript(typeof(Page), "SymbolError", 
 "<script type='text/javascript'>alert('Error !!!');</script>");
Sign up to request clarification or add additional context in comments.

5 Comments

Got error the name ClientScript doesn't exist in the current context.
Try to use Page.ClientScript
It also given the error An object reference is required for the non-static method,or property
try to google first related to that error and you got the answer for the question. Try to post a new question which is related to that
Thanks for your reply. I spent more time to solve this issue. But i can't.
-2

I know this is an old question.I am answering this to help new users who come across this question.

To use clientscript inside a static method pass the Page object as a parameter to your static method

protected void Page_Load(object sender, EventArgs e)
        {
           LoadJavascript(Page);
        }



public static void LoadJavascript( Page page)
        {

           page.ClientScript.RegisterStartupScript(page.GetType(), "alert", "<script>alert('Hai');</script>");
        }

1 Comment

because the question is that we want to call the javascript through the static method not the load time. First read question carefully then after give the answer according to the question

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.