I have a table tblProfile, which contains fields with Id, Name, Address. I have 2 aspx page, which are Home.aspx and Here.aspx. On my Home.aspx I have used this code to pass the Id in my Here.aspx:
<asp:HyperLink ID="link" runat="server" NavigateUrl="Here.aspx?id={0}"
Font-Names="Times New Roman" Font-Size="Medium" >Click here</asp:HyperLink>
In code behind Home.aspx.cs:
protected void Page_Load(object sender, EventArgs e)
{
string bID = Request.QueryString["Id"];
if (string.IsNullOrEmpty(Id))
{
Response.Redirect("Here.aspx?", true);
}
ViewState["Id"] = Id;
link.NavigateUrl = String.Format(link.NavigateUrl, Id);
}
I don't have any problem with passing the Id to url in 2nd page. But what I want right now is, on my Here.aspx, I have 3 textboxes which supposed to be filled by the Id, Name and Address of the certain Id that passed from the Home.aspx. Tried many but had no luck at all. Any help would be appreciated. By the way, I'm using asp.net with c#.
We are having two solution for it
Solution 1 : User Previous page property in asp.net so that you no need to pass ID. i.e.
protected void Page_Load(object sender, EventArgs e)
{
// Find the name on the previous page
TextBox txt = (TextBox)Page.PreviousPage.FindControl("txtNameText");
if (txt != null)
txtName.Text = Server.HtmlEncode(txt.Text);
else
txtName.Text = "[Name Not available]";
}
Solution 2 : Get ID from query string and get Data by ID in assign on text box text property.i.e.
protected void Page_Load(object sender, EventArgs e)
{
// Get value from query string
string profileID = Request.QueryString["Id"];
// Fetch data from database by ID
DataTable dt = FetchEmployeeDataByID(ProfileID);
txtName.text = dt.rows[0]["Name"].tostring();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With