Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
USING EXTENSION METHODS FOR GENERAL FUNCTIONALITIES
WhatsApp
Jaish Mathews
15y
6
k
0
0
25
Blog
1. 1st one, a replacement for RegisterStartUpScript. We can use this method in place and can be called from all pages.
2. 2nd one is additional method for "String" class.
Just try these and put your investments too.
HTML
<html xmlns="
http://www.w3.org/1999/xhtml
">
<head>
<title>Untitled Page</title>
<script language="javascript" type="text/javascript">
function pageLoad()
{
var submitButton = $get(g_SubmitButton);
submitButton.click();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Button ID="submitButton" runat="server" Text="Button" OnClientClick="javascript:alert('You clicked me');return false;" />
</form>
</body>
</html>
Coding
namespace WebApplication1
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Page.ClientScript.RegisterScriptVariable("g_SubmitButton",submitButton.ClientID,true);
string name = "C-SHARP CORNER";
string helloName = name.HelloString();
}
}
//Class contains Extension Methods
public static class ExtesionMethodClass
{
//Extender method for ClientScriptManager
public static void RegisterScriptVariable(this ClientScriptManager sm, string variableName, string variableValue, bool declareVariable)
{
string declaration = declareVariable ? "var " : string.Empty;
sm.RegisterClientScriptBlock(typeof(Page), variableName, String.Format("{0}{1} = '{2}';\r\n", declaration, variableName, variableValue.ToString().ToLower()), true);
}
//Extender method for String
public static string HelloString(this String str)
{
return string.Concat("Hello ", str);
}
}
}
Up Next
Create Unit Test Methods for Entities using Shim and Fakes
Ebook Download
View all
ASP.NET MVC 5: A Beginner’s Guide
Read by 28.1k people
Download Now!
Learn
View all
Membership not found