-1

I have a problem with a project which I'm doing in Visual Studio, using ASP.NET and C#.

I have one form where I list all the customers from database. The Id is autogenerated from the database. At this form I have a button for updating a record, when users press this button the second form shows up ready to change any field of the record. So far so good

But, at the second form I want to save the changes and I need the Id, but anything I have tried the Id comes with value 0...

I have tried all the methods like using session, query string, post back etc., but the id is not transferring to the 2nd page

First page:

    Response.Redirect("ProjectProductivityEst.aspx?id=" +ProInfIdtxt.Text);

Second page:

 string id = Request.QueryString["id"].ToString();
 ProjectInformationIdtxt.Text = Int32.Parse(id).ToString();
  • `Session["id"].ToString()` what do you get from session here? Did you consider passing the id as a querystring parameter to the next form while redirecting? `Response.Redirect("ProjectProductivityEst.aspx?id=" + ProInfIdtxt.Text );` – Chetan Oct 28 '22 at 07:06
  • @chetan yes, i have tried using querystring but still the value is not transferring. – Harshitha Murthy Oct 28 '22 at 07:34
  • 1
    Can you share the code of passing via querystring too? How are you trying to get the value from query string in the next page? – Chetan Oct 28 '22 at 08:31
  • @chetan 'string id = Request.QueryString["id"].ToString(); ProjectInformationIdtxt.Text = Int32.Parse(id).ToString();' this is how im using the code – Harshitha Murthy Oct 28 '22 at 09:07
  • Do you see the query string parameter with value in the browser address bar? What value are you getting in `id` variable? Please update the question and share the further code there instead of sharing via comments. Also can you share in which event of page you are trying to access the querystring or session in the second page? – Chetan Oct 28 '22 at 09:18
  • in the second page i used the querystring code in pageload event, the 'id' variable is not getting any values. – Harshitha Murthy Oct 28 '22 at 09:39

1 Answers1

0

If you are using the RazorPages or Razor view, you can just add this to your view.

<input type="hidden" asp-for="NameOfYourIdInModel" />

This creates a hidden input field in your html and sends an Id to your model when the user clicks the update button.

Weldis
  • 103
  • 1
  • 5