How to call the function of the content page from the main page

You must call the function of the content page from the main page. Please let me know if additional data is needed.

MasterPage.master.cs looks like

 protected void Required_Function(object sender, EventArgs e)
 {
    // call Update_Content_Page() from content page 
 }

Default.aspx looks like

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<asp:Content ID="Content1" ContentPlaceHolderID="contentPlaceHolder" Runat="Server">

<asp:Label ID="Label1" runat="server" Text="Label">Hello people!</asp:Label>

</asp:Content>

Default.aspx.cs looks like

usingpublic partial class _Default : System.Web.UI.Page
{ 
    protected void Update_Content_Page()
    {
        Label1.Text="Hello world";
    }
}
+5
source share
3 answers

you can try like this .. not really, but help you .....

You can inherit your page from the base class. Then you can create a virtual method in your base class, which will be overridden on your page. Then you can call this virtual method from the main page as follows:

(cphPage.Page as PageBase).YourMethod();

cphPage - ContentPlaceHolder . PageBase - , YourMethod.

+6

, , MasterPage ContentPage, . MasterPage ContentPages. , , CodeProject

+1

jquery: , "saveButton" :

HTML:

enter code here

.master jquery code:

function tester() {
        console.log("Testing");
        $("[id$='SaveButton']").click();
    }

I used id $ = 'SaveButton' because, as you now know, ASP.NET renames controls when they are inside the wizard, repeater, grid, and other controls. $ id = 'stuff' verifies that the control identifier ends with "stuff".

+1
source

All Articles