Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7089357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:54:43+00:00 2026-05-28T07:54:43+00:00

I have a textbox in asp page which is a concrete view. User enters

  • 0

I have a textbox in asp page which is a concrete view. User enters a string of 2000 characters long. When save button is pressed, this value is saved into database. After save the page I redirected to another page where the entered value is shown as a label. I used to store the value of the textbox in session. How do I handle it when I am using it in MVP?

1) How to set the value of session using MVP concepts in TextInputPage?

2) How to display the result in label after reading from session using MVP concepts?

Note: There is some processing (text appending) before adding value to session.

It would be great if you can answer with code example rather than pointing to another post. This is the moste simplest example (I think 🙂 ) for new comers to learn.

using System;
namespace ViewInterfaces
{
public interface ITextView
{
    string InputtedText { get; }
    event EventHandler ButtonClickedEvent;
}

}

<form id="form1" runat="server">
<div>

    <asp:TextBox ID="txtInput" runat="server"></asp:TextBox>

&nbsp;<asp:Button ID="btnGoToResult" runat="server" Text="Go To Result" 
        onclick="btnGoToResult_Click" />

</div>
</form>


using System;
using ViewInterfaces;
using Presenter;
using Model;

public partial class TextInputPage : System.Web.UI.Page, ITextView
{

public event EventHandler ButtonClickedEvent;
private TextPresenter listPresenter;

protected void Page_Load(object sender, EventArgs e)
{
    TextModel modelController = new TextModel();
    listPresenter = new TextPresenter(this, modelController);
    this.listPresenter.OnViewLoaded();
}

public string InputtedText
{
    get
    {
        return txtInput.Text;
    }
}


protected void btnGoToResult_Click(object sender, EventArgs e)
{

    if (ButtonClickedEvent != null)
    {
        //Riase the event
        ButtonClickedEvent(this, e);
    }


    //Session does not use any MVP now.
    if (txtInput.Text.Length > 0 && txtInput.Text.Length <= 100)
    {
        Session["TextInput"] = "1-100 "+txtInput.Text;
    }
    else if (txtInput.Text.Length > 100 && txtInput.Text.Length <= 1000)
    {
        Session["TextInput"] = "101-1000" + txtInput.Text;
    }
    else
    {
        Session["TextInput"] = "1001 - 2000" + txtInput.Text;
    }


    //Redircting currenlty does not use any MVP concept
    Response.Redirect("/SessionTestWebSite/ResultOutputPage.aspx");
}

}

  <form id="form1" runat="server">
    <div>

    <asp:Label ID="lblResult" runat="server" Text="Label"></asp:Label>

</div>
</form>

using System;
public partial class ResultOutputPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
    //Does not use MVP now
    lblResult.Text = (string) Session["TextInput"];
}

}

using System;
using ViewInterfaces;
using Model;

namespace Presenter
{
public class TextPresenter
{
    private ITextView viewObj;
    private TextModel contactsModelController;

    public TextPresenter(ITextView view, TextModel controller)
    {
        viewObj = view;
        contactsModelController = controller;
    }

    //Presenter Method 
    public virtual void OnViewLoaded()
    {
        //Event subscription
        viewObj.ButtonClickedEvent += new EventHandler(DetailView_EditClicked);

    }

    void DetailView_EditClicked(object sender, EventArgs e)
    {
        //Calling Model's Functionality
        contactsModelController.StoreText(viewObj.InputtedText);
    }

}

}

namespace Model
{
public class TextModel
{
    public void StoreText(string inputString)
    {
        //Store to database
    }

}

}

References:
mvp session response request

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T07:54:44+00:00Added an answer on May 28, 2026 at 7:54 am

    I usually use next way:

    public interface ITextView
    {
        string InputtedText { get; }
        string SessionTextEntry { get; set; }
        void RedirectToTestPage();
    
        event EventHandler ButtonClickedEvent;
    }
    

    View implementation:

    public partial class TextInputPage : System.Web.UI.Page, ITextView
    {
        ...
    
        public string SessionTextEntry 
        { 
            get { return (string)Session["TextInput"]; }
            set { Session["TextInput"] = value; }
        }
    
        public void RedirectToTestPage()
        {
            Response.Redirect("/SessionTestWebSite/ResultOutputPage.aspx");
        }
    
        ...
    }
    

    Presenter:

    public class TextPresenter
    {
        ...
    
        void DetailView_EditClicked(object sender, EventArgs e)
        {
            //Calling Model's Functionality
            contactsModelController.StoreText(viewObj.InputtedText);
    
            // Save to session and redirect
            viewObj.SessionTextEntry = GetTextForSession(viewObj.InputtedText);
            viewObj.RedirectToTestPage();
        }
    
        // data processing logic
        private string GetTextForSession(string inputtedText)
        {
            if (inputtedText.Length > 0 && inputtedText.Length <= 100)
                return "1-100 " + inputtedText;
    
            if (inputtedText.Length > 100 && inputtedText.Length <= 1000)
                return "101-1000" + inputtedText;
    
            return "1001 - 2000" + inputtedText;
        }
    
        ...
    }
    

    In this case used only setter of ITextView.SessionTextEntry so getter can be removed.
    Hope it helps…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to have a textbox on a ASP.NET page in which a user
I have a .Net page with some textboxes, which are sometimes disabled. <asp:TextBox ID=TextBox1
I have a custom search control on my page (asp.net) which contains a textbox
I have user control named DateTimeUC which has two textboxes on its markup: <asp:TextBox
I have an asp.net page for a simple blog which looks like <asp:TextBox ID=txtContent
I have an aspx page and a asp textbox control which has ajax autoCompleteExtender.
I have an ASP page which displays a text box when it loads. It
I have the following textbox server control in my web page: <asp:TextBox ID=txtZip runat=server
I have <asp:TextBox runat=server ID=lastName /> on a page and I want to set
I have a ASP.NET web page that contains many textboxes. Each textbox has a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.