Results 1 to 6 of 6

Thread: Passing variable to another page

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    3

    Passing variable to another page

    This is my first post on these forums so I apologise if it's a common problem. I'm fairly new to ASP.NET.

    The situation is as follows:

    On one web page, I have created some textboxes where users can search for records in a db (SQL Sever 2005 Beta). The results of their search are then displayed in a datagrid.

    The datagrid also has two 'hyperlink' columns which the user can click to be redirected to other pages where related data is displayed. I use the 'URL format string' property of the hyperlink column to display the correct record by using the following string: NameOfForm.aspx?patid={0}. All of this works fine.

    One of the hyperlink columns takes the user to a second aspx page which contains a datagrid and shows the many records related to the record the user originally searched for. This second datagrid also has two 'hyperlink' columns, 'Add' and 'Edit'.

    These do pretty much as they say. 'Add' allows the user to add a record to the many end of a database relationship, and 'Edit' displays the specific record selected for editing\viewing. Once again all works well so far.

    The problem comes when the datagrid on the second web form is empty (i.e. there are no records in the related table in the db) and the hyperlink columns are not visible. I thought I'd get around this by adding a 'Hyperlink' control to my web form. This redirects the user to a web form where a related record can then be added.

    This also works but I what I need is the correct 'patid' to be passed onto this page, which is required as the foreign key of the relationship. How can I pass this variable to the next page?

    I hope I've described the problem clearly enough.

    TIA,

    Mo

  2. #2
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131

    Re: Passing variable to another page

    You can pass the patid in the same way you did in the URL before (NameOfForm.aspx?patid={0}).

    You can populate it from Request.QueryString["patid"] - which will grab the value you passed before.

    Hope that makes sense.

    DJ

    If I have been helpful please rate my post. If I haven't tell me!

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    3

    Re: Passing variable to another page

    Quote Originally Posted by dj4uk
    You can pass the patid in the same way you did in the URL before (NameOfForm.aspx?patid={0}).

    You can populate it from Request.QueryString["patid"] - which will grab the value you passed before.

    Hope that makes sense.

    DJ
    Thanks for the reply DJ.

    I have already used Request.QueryString ("patid") on the target page. This works fine when the 'sending' page has records to display. When there are no records in the datagrid, the 'patid' does not get passed on. The url field in the target page reads 'http://localhost/Ertocs/AddCancers.aspx?patid={0}' which is not what I'm expecting.

    I've set the 'Navigate URL' property of the hyperlink control to 'AddCancers.aspx?patid={0}'. Is this correct or am I missing something simple? Thanks again for your help.

    I must be doinf something wrong

  4. #4
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131

    Re: Passing variable to another page

    I presume you are using Response.Redirect to get to the target page.

    Use:
    Code:
    Response.Redirect(String.Format("AddCancers.aspx?patid={0}", Request.QueryString["patid"]));
    You are not specifying what needs to be placed at the 0 index.

    HTH

    DJ

    If I have been helpful please rate my post. If I haven't tell me!

  5. #5

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    3

    Re: Passing variable to another page

    Quote Originally Posted by dj4uk
    I presume you are using Response.Redirect to get to the target page.

    Use:
    Code:
    Response.Redirect(String.Format("AddCancers.aspx?patid={0}", Request.QueryString["patid"]));
    You are not specifying what needs to be placed at the 0 index.

    HTH

    DJ
    Thanks for the help DJ. In the end I changed the hyperlink control to a link button with this code:

    Server.Transfer("AddCancers.aspx")

    with Request.Querystring("patid") in the target page and it works!

  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Passing variable to another page

    Check if the datatable/dataset is Nothing, and if that condition is true, set the visibility of your hyperlink control to true.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width