Can I Set a Div Inner Html in Mvc Controller Action Method
-
- Updated date Apr 13, 2020
- 71.1k
- 2
This article shows how to use the GetElementById function with the InnerHTML property in ASP.Cyberspace using JavaScript.
Introduction
This article shows how to employ the GetElementById office with the InnerHTML property in ASP.Cyberspace using JavaScript. In this commodity, you will see how to go the id of the HTML element using the GetElementById function and apply it with the InnerHTML property. Outset start Visual Studio .NET and make a new ASP.Net web site using Visual Studio 2010.
GetElementById Part
The getElementById function refers to the HTML chemical element using its ID. The id property sets or returns the id of an element.
- <script type= "text/javascript" >
- ShowID() {
-
Getid = certificate.getElementById( 'TextMessage' ); - warning(Getid.id);
- }
- </script>
Output
What is Inner HTML Property?
The inner HTML belongings can be used to modify an HTML document. The innerHTML property exists in all types of major browsers. When you lot apply innerHTML, you can change the page's content without refreshing the page. This can make your website feel quicker and more responsive to user input.
Syntax
The syntax for using innerHTML looks like this:
document.getElementById('ID of element').innerHTML = 'Data or content';
- getElementById: The getElementById refers to the HTML chemical element using its ID.
- Information or content: Data is the new content to go into the element.
So to make information technology work use the following JavaScript function lawmaking in your folio:
- <script blazon= "text/javascript" >
- function ShowMessage() {
- document.getElementById('TextMessage' ).innerHTML = 'C-sharpCorner' ;
- }
- </script>
Now elevate and drop a Button Control onto the form such that you take:
- <input type= "push button" onclick= "ShowMessage()" value= "Show Message" />
- <p id="TextMessage" ></p>
Instance
- <%@ Page Language= "C#" AutoEventWireup= "true" CodeFile= "RefreshPage.aspx.cs" Inherits= "RefreshPage" %>
- <!DOCTYPE html PUBLIC"-//W3C//DTD XHTML ane.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
- <html xmlns="http://www.w3.org/1999/xhtml" >
- <caput runat="server" >
- <title></title>
- <script type="text/javascript" >
- function ShowMessage() {
- document.getElementById('TextMessage' ).innerHTML = 'C-sharpCorner' ;
- }
- </script>
- </head>
- <torso>
- <form id="form1" runat= "server" >
- <div>
- <input type="button" onclick= "ShowMessage()" value= "Testify Message" />
- <p id="TextMessage" ></p>
- </div>
- </form>
- </body>
- </html>
Output
Source: https://www.c-sharpcorner.com/UploadFile/rohatash/using-getelementbyid-function-with-innerhtml-property-in-jav/
0 Response to "Can I Set a Div Inner Html in Mvc Controller Action Method"
Post a Comment