Answered by:
Error - The name clientscript does not exist in the current context.

Question
-
User-1499457942 posted
Hi
On this it shows message this is not valid in Static property , static method.
public class CommonFunction { public static string Test() { try { } catch (Exception ex) { ClientScript.RegisterStartupScript(this.GetType(), "Popup", "ShowPopup('" + CommonFunction.ErrorMessage + "');", true); } } }
Thanks
Monday, August 27, 2018 5:50 PM
Answers
-
User-893317190 posted
Hi JagjitSingh ,
Static method belongs to class level , it is called through the class. "This" refers to current instance of the class. Static method of class is prior to instance of the class ,so you couldn't visit "this" in your static method.
Please refer to https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/static to learn more about static.
You could change it to instance method.
Best regards,
Ackerly Xu
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, August 28, 2018 4:19 AM -
User-369506445 posted
hi
here you have many mistakes,
first ClientScript is available for classes that derived from Page Class for example
public partial class WebForm1 : System.Web.UI.Page
now in Webform1, you access to ClientScript
second, you define a property that returns a string and the ClientScript not run any time
I suggest you return a string in your property and then put the result in a ClientScript in your context
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, August 28, 2018 4:30 AM
All replies
-
User-893317190 posted
Hi JagjitSingh ,
Static method belongs to class level , it is called through the class. "This" refers to current instance of the class. Static method of class is prior to instance of the class ,so you couldn't visit "this" in your static method.
Please refer to https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/static to learn more about static.
You could change it to instance method.
Best regards,
Ackerly Xu
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, August 28, 2018 4:19 AM -
User-369506445 posted
hi
here you have many mistakes,
first ClientScript is available for classes that derived from Page Class for example
public partial class WebForm1 : System.Web.UI.Page
now in Webform1, you access to ClientScript
second, you define a property that returns a string and the ClientScript not run any time
I suggest you return a string in your property and then put the result in a ClientScript in your context
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, August 28, 2018 4:30 AM