Passing value to another page on Link Click using C# in ASP.Net

RichardSa
 
on Sep 03, 2021 11:17 PM
492 Views

I have 4 webforms (create.aspx, grid.aspx, summary.aspx, voter.aspx).

I create an election on create.aspx  and click on button to redirect to summary.aspx and all the values of create.aspx are passed. Then I navigate to voter.aspx with <li><a href="voter.aspx"></a></li>, those same values passed from create.aspx to summary are displayed in voter.aspx.

Then in grid.aspx there is a GridView that shows all the elections created. When I click on a GridView row, it redirects to summary.aspx with row values passed. After these values are passed to summary, I click on the navigation link item in summary to redirect to voter.aspx and pass the same values which came from that GridView row in grid.aspx, but it's the other election I created from the create.aspx that shows. How can I make it that whenever I navigate from either creating election to summary to voter OR GridView row to summary to voter, the values will be passed according to where user navigates from?

NOTE: From gridview.aspx to summary.aspx and create.aspx to summary it's GridView row click and button click, but from summary to voter.aspx it's navigation link item

The page "voter.aspx" displays values passed from summary.aspx. Then "summary.aspx" displays values passed from either create.aspx OR grid.aspx.

**summary.aspx uses link item to redirect to voter.aspx

Download FREE API for Word, Excel and PDF in ASP.Net: Download
RichardSa
 
on Sep 08, 2021 06:02 AM

I resolved that by displaying data of table and using the data for each user based on userID and particular url that represents the event

public void ShowUserData()
{
    SqlConnection con = new SqlConnection("Data Source = (LocalDB)\\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\\BallotDB.mdf;Integrated Security = True;");
    con.Open();
    SqlCommand cmd = new SqlCommand();
    cmd.CommandText = "SELECT * FROM Table WHERE Url = '" + Session["EventURL"] + "' AND Id = '" + Session["user"] + "'";
    cmd.Connection = con;
    SqlDataAdapter sda = new SqlDataAdapter();
    DataSet ds = new DataSet();
    sda.SelectCommand = cmd;
    sda.Fill(ds, "detail");
    if (ds.Tables[0].Rows.Count > 0)
    {
        UserID.Text = ds.Tables[0].Rows[0][0].ToString();
        namelbl.Text = ds.Tables[0].Rows[0][1].ToString();
        lblElection.Text = ds.Tables[0].Rows[0][3].ToString();
        startlbl.Text = ds.Tables[0].Rows[0][4].ToString();
        endlbl.Text = ds.Tables[0].Rows[0][5].ToString();
        Labelurl.Text = ds.Tables[0].Rows[0][6].ToString();
    }
}