6 Replies - 2915 Views - Last Post: 04 June 2011 - 12:59 PM Rate Topic: -----

#1 svpam123   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 47
  • Joined: 01-April 11

passing parameters between pages + parameters in text input.

Posted 03 June 2011 - 11:48 AM

hey, I have 2 questions regarding a site I'm working on.
I'm new to ASP and I'm having some trouble with a couple of things...
I found answers to one of the questions in google but couldn't actually understand how to use the suggestions...

1. I want to pass parameters from one ASP page to another. for example - I'm going to have a search page, people enter a User ID into the search box, and when they submit it an asp page is called which retrieves all the information about the user from my SQL table, and they're saved as variables.
example -
information is retrieved -
"Select * from tbl2 where ( UserId = '" + UserId + "')";
and then in order to write the first name on the screen I do this -
ds.Tables[0].Rows[0]["Fname"]
same goes for the other things like last name, email, age and so on.
I want to use these parameters on other ASP pages. how do I do that?
I actually found results in google for this but I can't understand how to implement them so I could really use some help :)

2.I've retrieved information about a user from my SQL table, and I want this information to be written in an html input field.
for example -
<input type="text" value="ABC">
instead of the 'ABC' I want to have something that was retrieved from the database. is it possible? if so, how?

thanks a lot!

Is This A Good Question/Topic? 0
  • +

Replies To: passing parameters between pages + parameters in text input.

#2 svpam123   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 47
  • Joined: 01-April 11

Re: passing parameters between pages + parameters in text input.

Posted 03 June 2011 - 12:58 PM

okay I found the problem I had with question number 1.
I tried using Sessions but didn't use the syntax properly :)

help needed just for 1.
thanks
Was This Post Helpful? 0
  • +
  • -

#3 Nakor   User is offline

  • Professional Lurker
  • member icon

Reputation: 448
  • View blog
  • Posts: 1,504
  • Joined: 28-April 09

Re: passing parameters between pages + parameters in text input.

Posted 03 June 2011 - 06:44 PM

How are you retrieving it from the database? Is this just a free standing textbox or is it in a databound control of some sort like a gridview or listview?
Was This Post Helpful? 0
  • +
  • -

#4 svpam123   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 47
  • Joined: 01-April 11

Re: passing parameters between pages + parameters in text input.

Posted 03 June 2011 - 10:52 PM

View PostNakor, on 03 June 2011 - 06:44 PM, said:

How are you retrieving it from the database? Is this just a free standing textbox or is it in a databound control of some sort like a gridview or listview?

hey
the data is retrieved like this, in a <% %> code -
"Select * from tbl2 where ( UserId = '" + UserId + "')"
and then I get the data about UserId like this -
ds.Tables[0].Rows[0]["Fname"]
ds.Tables[0].Rows[0]["Lname"]
and so on.

my input box is in a form tag -
<form id="f1" action="UpdateData.aspx" method="post">
<br />
<br />
    <div>
    Edit user information:
    <br />
    First name: 
        <input id="Fname" name="Fname" type="text" />
    <br />
    Last name: 
        <input id="Lname" name = "Lname" type="text" />
    <br />
    Email: 
        <input id="Email" name="Email" type="text" />
    <br />
    Age:
    <input id="Age" name="Age" type="text" />
    <br />

        <input id="Submit1" type="submit" value="Edit!" />

           </div>
       
    </form>


what I want is that every text box will have an initial value which will be matching to the box. (Lname will have ds.Tables[0].Rows[0]["Lname"]and so on).

I'm sorry that I didn't really answer your question because I'm new to this and don't know the exact terms for everything, soI can't really explain myself :)

however, since I've explained what I'm trying to do, I thought I might ask for a suggestion -
I'm doing this because I want the user to edit his information, but I didn't know what to do if he leaves a field blank.
I didn't know how to write an update query that ignores blanks and couldn't find an answer on google, so I thought I should have the values he wants to edit written inside the text box. this way, if he doesn't change anything and will press submit, then basically the old values will stay.
will this work? is it even a good idea? is there another solution?

thanks!

This post has been edited by svpam123: 03 June 2011 - 10:52 PM

Was This Post Helpful? 0
  • +
  • -

#5 Nakor   User is offline

  • Professional Lurker
  • member icon

Reputation: 448
  • View blog
  • Posts: 1,504
  • Joined: 28-April 09

Re: passing parameters between pages + parameters in text input.

Posted 03 June 2011 - 11:50 PM

In this situation I would probably just use a DetailsView connected to a data source such as the SqlDataSource control.

MSDN: (The DetailsView Control) Displays the values of a single record from a data source in a table, where each data row represents a field of the record. The DetailsView control allows you to edit, delete, and insert records.

DetailsView Class

However, if you want to do it the more manual way then the easiest way to set the TextBox values initially would be to set the Text property when you run you're select statement.

Fname.Text = ds.Tables[0].Rows[0]["Fname"].ToString();



or are you wanting to populate the textboxes using values stored in Session variables? If that's the case in the Page_Load event you would just do something like

Fname.Text = (string)Session["Fname"];


This post has been edited by Nakor: 04 June 2011 - 12:00 AM

Was This Post Helpful? 0
  • +
  • -

#6 svpam123   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 47
  • Joined: 01-April 11

Re: passing parameters between pages + parameters in text input.

Posted 04 June 2011 - 12:36 AM

View PostNakor, on 03 June 2011 - 11:50 PM, said:

In this situation I would probably just use a DetailsView connected to a data source such as the SqlDataSource control.

MSDN: (The DetailsView Control) Displays the values of a single record from a data source in a table, where each data row represents a field of the record. The DetailsView control allows you to edit, delete, and insert records.

DetailsView Class

However, if you want to do it the more manual way then the easiest way to set the TextBox values initially would be to set the Text property when you run you're select statement.

Fname.Text = ds.Tables[0].Rows[0]["Fname"].ToString();



or are you wanting to populate the textboxes using values stored in Session variables? If that's the case in the Page_Load event you would just do something like

Fname.Text = (string)Session["Fname"];


hey
first of all - thanks!

I didn't really understand how to use the DetailsView class, so I'll go with the second suggestion.
I'm not passing the values as a session, so the first suggestion will be good.
thing is, and this might be a dumb question - I don't know where to put the
Fname.Text = ds.Tables[0].Rows[0]["Fname"].ToString();


I assume the Fname is related to the ID of the text box,
<input id="Fname" name="Fname" type="text" />
right?

I don't know where to put the Fname.Text = ...

better ask a stupid question and learn than stay stupid :)
sorry and thanks again!
Was This Post Helpful? 0
  • +
  • -

#7 Nakor   User is offline

  • Professional Lurker
  • member icon

Reputation: 448
  • View blog
  • Posts: 1,504
  • Joined: 28-April 09

Re: passing parameters between pages + parameters in text input.

Posted 04 June 2011 - 12:59 PM

put it in the Page_Load event, to get to the code behind file press F7 when you're looking at the aspx page (the on with the html on it).
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1