Jump to content

Change Textbox.text load page based on changes


bblbailey3

Recommended Posts

Hello again...still pretty new at this and I have something that I guess is rather odd that I am trying to do.The basic idea is this.Page 1 has multiple links. All of them point to Page 2. On Page 2 I would like to display information using an asp:label based on which link was clicked in the first screen.I have tried using the onlick command to change a "hidden" textbox's value and then load the page. The new page then reads the passed value and displays the correct info:Sub Button1onclick(sender As Object, e As System.EventArgs)TextBox.text="Button1"server.transfer("Page2.aspx", true)End Sub(A respective sub like this exists for each Button/Link/etc.)However the transfer occurs before the change to the TextBox and so Page 2 displays the information for whatever the text box value read prior to the buttonclick.Basically I could even use the OnTextChanged event if I could figure out how to "force" the browser to realize the text had changed...I'm sure a lot of you are wondering why do this at all...Why not just create separate pages for each link? For one I guess I'm a bit crazy and two I get confused trying to deal with tons of different pages. Reason three: Because I've peaked my interest in trying to solve this problem. Also, I do not want to display the information on the same page as that would cause a whole set of other problems.Hope someone can help.

Link to comment
Share on other sites

Found a solution not using the stupid text box too...Using the Context Items stuff Sub Button1onclick(sender As Object, e As System.EventArgs)Context.Items.add("TextBox","text")server.transfer("Page2.aspx", true)End SubThen on the second page if Context.Items("Textbox") = "text" then Label1 = "Blah Blah Blah"

Link to comment
Share on other sites

Yeah, the Click event for buttons and hyperlinks is handled AFTER the Load event for the page. One way you might do it would be something like the following (pardon my C#, I don't do VB):

protected void MyLink_Click(object sender, EventArgs e){	Button button = (Button)sender;	Server.Transfer("Page2.aspx?id=" + button.ID);}

Then, on the second page, get the value of the button id like so:

protected void Page_Load(object sender, EventArgs e){	string buttonID = String.Empty;	if(String.IsNullOrEmpty(Request["id"]) == false)	{		buttonID = Request["id"];	}}

Link to comment
Share on other sites

don't you mean Request.QueryString["id"] ???
You can use both, I rarely, if ever, use Request.QueryString["id"]. I almost always use Request["id"]. The only time I ever use the QueryString property is to get the entire QueryString.
Link to comment
Share on other sites

huh, didn't know that. I have been using C# for almost 3 years too :)
hah! That's how I felt when you told me I could simply do:
mystring.Split(',');

Rather than

mystring.Split(new char[] {','});

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...