1

i am dynamically create contents and buttons into my code behind "tree.aspx.cs" page

sbmainTbl.AppendFormat("<tr><td><div class=\"a\">{0}<div class=\"details\"<p id=\"p\">{1}</p><ul><li>Parent-UnitId:{2}</li><li>Address :{3}</li><li>City: {4}</li><li>EmailId: {5}</li><li>PhoneNo: {6}</li><li>FaxNo: {7}</li><li><input type=\"button\" value=\"ADD\"  onclick=\"f2();\" /></li></ul></div></div></div></td></tr>",
            CellText(dtparent.Rows[0]["UnitName"].ToString()),
            CellText(dtparent.Rows[0]["UnitName"].ToString()),
            CellText(dtparent.Rows[0]["ParentUnitId"].ToString()),
            CellText(dtparent.Rows[0]["Address"].ToString()),
            CellText(dtparent.Rows[0]["City"].ToString()),
            CellText(dtparent.Rows[0]["EmailId"].ToString()),
            CellText(dtparent.Rows[0]["PhoneNo"].ToString()),
        CellText(dtparent.Rows[0]["FaxNo"].ToString()));

Now i have another page called "Add.aspx Page" in that page i have textbox

<asp:TextBox ID="txtunitname" runat="server" CssClass="textbox"></asp:TextBox>

now i just want on click on dynamically create button on "tree.aspx" page the "unitname(dynamically create value)" will pass "Add.aspx" page and textbox should fill with unitname.

kindly help me, Thanks.

Lijo
  • 6,498
  • 5
  • 49
  • 60
akvickyit7
  • 225
  • 1
  • 4
  • 16
  • 1
    Are we talking about two pages in two browser tabs/windows? Or do you call tree.aspx, press a button and navigate to add.aspx? – Alexander Jan 10 '14 at 12:26
  • you can store the value in [sessions](http://msdn.microsoft.com/en-us/library/ms178581.aspx) and get the session value in another page. – Ravimallya Jan 10 '14 at 12:29
  • i call tree.aspx page and on press dynamic create button i will navigate to add.aspx page. – akvickyit7 Jan 10 '14 at 12:38
  • 1
    Well then, either write the values into the Session, as @Ravimallya suggests, or hand the values over in the Query Parameter. – Alexander Jan 10 '14 at 12:41
  • well the problem is that the contents i have created dynamically are in a
    and the
    appeared lot of times in page and every time it's have different values thats why i create a dynamic button along this and on clicking that button the values in that specific
    navigate to Add.aspx page.
    – akvickyit7 Jan 10 '14 at 12:45

1 Answers1

0

To pass pass values using asp.net you need to follow the asp.net way.

First on the first page you place that value on a page control, I prefer on your case a hidden field, that is also post back to any page.

Then you add your value to that field

ValueHiddenField.value = CellText(dtparent.Rows[0]["UnitName"].ToString())

and you make also a public field so the second page can read it

public string ValueHiddenField
{
    get
    {
        return ValueHiddenField.value;
    }
}

And you say to the button to post back to the second page using the PostBackUrl field of the button.

Now this is the way you get your data from second page:
On the redirect page declare what is the previous page on aspx as:

<%@ Reference Page ="~/PreviousPageName.aspx" %>

and on code behind on second page you get the value as:

if (Page.PreviousPage != null)
{
    if (Page.PreviousPage is PreviousPageClassName)
    {
        Label1.Text = ((PreviousPageClassName)Page.PreviousPage).ValueHiddenField;
    }
    else
    {
        Label1.Text = "no value";
    }
}
else
    Label1.Text = "no value from previous page";

Similar answers: cross page posting
Cross-page posting. Is it a good pratice to use PreviousPage in Asp.net?

Aristos
  • 66,005
  • 16
  • 114
  • 150
  • hi @Aristos i am doing the same but the problem is i am getting Page.PreviousPage = null so can't go in the first loop. help me to fix it – akvickyit7 Jan 13 '14 at 07:20
  • @akvickyit7 You can also use the `Form[]` to direct read all posted values. – Aristos Jan 13 '14 at 08:55