We help IT Professionals succeed at work.

Javascript injection

samprg
samprg used Ask the Experts™
on
Hi,
I am trying to inject javasript from codebehind:

StringBuilder sb = new StringBuilder();
            sb.Append("<script language=javascript>\n");
             .
             .
             .
           sb.Append("</script>\n");  
But I get error in    Page.RegisterClientsideScript("script ", sb.ToString());
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
What is the error you are receiving?
Use this code::
Change your line from
Page.RegisterClientsideScript("script ", sb.ToString());

Open in new window


to:
Page.RegisterClientScriptBlock("script ", sb.ToString());

Open in new window

and see what happens ;)

Author

Commented:
System.Web.UI.Page' does not contain a definition for 'RegisterClientsideScript' and no extension method 'RegisterClientsideScript' accepting a first argument of type 'System.Web.UI.Page' could be found (are you missing a using directive or an assembly reference?)

Author

Commented:
No error but  my javascript does not work, I wen to View Source I found it under "<form..."

Author

Commented:
Awesome