简体   繁体   中英

Event before redirect to another page

I've just developed a new GridView MultiFilter control ( CompositeControl ) that works like the image below:

多滤镜图像

I use ViewState for my control's properties so it keeps all values after postback. I want to save my control properties to a Session before redirect so I can load properties back to my control when my page loads again.

Does anyone have any suggestions about how this can be accomplished?

You have to do 2 things in this list page:

  • (1)Page load
  • (2)Search click

And 1 thing in detail (redirected) page:

  • (3)Pass some query string while back to list page

(1)while page load decide to load normal or searched (back from detail page) data

protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
    if (Request.QueryString["back"] != null)
        bindDataFirst();
// same data load logic as present
    else
            bindDataForBack();
// you come back from detail page hence bind search & grid data
}

private void bindDataForBack()
    {

strName = Session["SearchName"] == null ? "" : Session["SearchName"].ToString();
// check session search conditions & data and bind

//also bind grid by respective search parameters & search options (top side)

(2)search click store search data into session

public void btnSearch_Click(object sender, System.EventArgs e)
    {

Session["SearchName"] = strName;// store search data into session variables

//bind grid by respective search parameters

(3)in redirected (detail) page set back button like:

public void btnBack_Click(object sender, System.EventArgs e)
    {
Response.Redirect("ListPage.aspx?back=1");

I hope this may helps you. I suggest to implement this with one textbox & grid and then try with your present scenario.

Please mark this answer useful if this solve your problem.

You can assign data to Session the pretty much the same way you assign to ViewState.

It's a key value dictionary just like ViewState.

Ex:

Session["someKey"] = "An arbitrary value";

If you can redirect to another page using form submit then You can post your form to the required page using action attribute of your page. This way values of all controls will be available in the Request["KEY NAME HERE"]

<form action="anotherpage.aspx" id="frmData">
<!-- YOUR CONTROLS HERE -->
<input type="submit" value="Submit" />
</fomr>

you can also submit your form using JS

$("#frmData").submit();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM