2

In the ASP.NET Master Page (.Master) there is a text-box that should filter the content in a website. To do it I would like to call the function GetMessageLogs in the .aspx.cs file.

Site.Master:

<button onclick="containCatText()" class="catbtn">Category</button>
<div id="myDropdownCat" class="catdown-content">
    <input type="text" placeholder="Search.." id="myCat" onkeyup="filterFunction()">
</div>
<script>
    var myCat = document.getElementById("myCat").value;
</script>

Feeds.aspx:

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Feeds.aspx.cs" Inherits="ReportTool.Users.Feeds" %>

Feeds.aspx.cs:

namespace ReportTool.Users
{
    public partial class Feeds : System.Web.UI.Page
    {
        Inov.ReportTool rt = new Inov.ReportTool();    
        MessageLogs = rt.GetMessageLogs(null, Server.MapPath("/ReportTool/Photo") + "\\", Server.MapPath("/ReportTool/Video") + "\\", new DateTime(2016, 09, 15),DateTime.Now, "%J%","Tr");

My question is simply how do I replace the "%J%" in the Feeds.aspx.cs from the variable myCat from Site.Maste?

Bond
  • 21
  • 1

1 Answers1

0

If you want to use ASP.Net WebForms:

First, data in the myCat control can't be easily sent to a code-behind (.aspx.cs) page because myCat doesn't have the runat="server" property.

Additionally, WebForms is (typically) set up to have each page operate independently. There are ways around this (calling functions from your Site.Master code-behind page, using Session variables, using a database - these all involve creating a communication channel between the two pages you're using).

In my experience, it's much easier if the Master page had the search function in its code-behind.

If you want to use JavaScript instead

Since you have references to JavaScript functions, you may feel more comfortable following this path (or not - there isn't really a right answer here): if you want to use JavaScript and keep the search function were in a web API, Microsoft has a really in-depth walkthrough available here.

jwheron
  • 2,553
  • 2
  • 30
  • 40
  • Thank you for the answer but I have to restructure the whole project. Is there anything more direct? – Bond Sep 11 '18 at 22:10
  • You can reference data on a master page from a "child" page, but it's (in my opinion) a lot more complicated and error-prone. I'd suggest reading over this question (https://stackoverflow.com/questions/15573505/how-to-access-master-page-control-from-content-page) if you're interested in that. – jwheron Sep 13 '18 at 12:16