| |

VerySource

 Forgot password?
 Register
Search
View: 814|Reply: 9

Problems with screen value passing in ASP.NET

[Copy link]

7

Threads

15

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-1-4 16:40:01
| Show all posts |Read mode
I have a picture 1.aspx with a textbox and button inside
I add the following event to the button event:
Protected Sub Button1_Click (ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        TextBox1.Text = "aaaa"
End Sub
Then submit this picture to the next picture
<asp: Button ID = "Button1" runat = "server" Text = "Button" PostBackUrl = "~ / 2.aspx" />
Why can't I get the value of the previous screen with request.form ("textbox1") in the next screen (2.aspx)?
I enter the value in the text box in 1.aspx, and I can get the value in the next screen. But why can't I pay for the textbox in the click event and then the next screen can't be received?
Reply

Use magic Report

0

Threads

10

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-1-4 18:24:01
| Show all posts
Because you define PostBackUrl = "~ / 2.aspx", the page will not trigger your click event at all, which means that TextBox1.Text will never be assigned a value before submitting to 2.aspx, so in 2.aspx It is impossible to get
Reply

Use magic Report

0

Threads

64

Posts

35.00

Credits

Newbie

Rank: 1

Credits
35.00

 China

Post time: 2020-1-4 18:27:01
| Show all posts
How do you get and assign? You set breakpoints for debugging in both places to see if the click event is executed, and which interrupt is executed first, and which one is executed after?
Reply

Use magic Report

0

Threads

64

Posts

35.00

Credits

Newbie

Rank: 1

Credits
35.00

 China

Post time: 2020-1-4 22:57:01
| Show all posts
Because you define PostBackUrl = "~ / 2.aspx", the page will not trigger your click event at all
——————————————————————————————————————
Clicking on the PreviousPage fires the click event.
Reply

Use magic Report

7

Threads

15

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

 Author| Post time: 2020-1-5 00:06:01
| Show all posts
So what should I do? My screen must jump to 2.aspx, and the textbox in 1.aspx must be used after the button is clicked.
What should I do to solve it?
Reply

Use magic Report

0

Threads

64

Posts

35.00

Credits

Newbie

Rank: 1

Credits
35.00

 China

Post time: 2020-1-6 09:51:01
| Show all posts
Write in 2.aspx:

Page1 prev = (Page1) this.PreviousPage;
if (prev == null)
  throw new Exception ("1.aspx was not executed.");

TextBox txtboxOnPage1 = Page1.TextBox1;

And Text of txtboxOnPage1 can get the value after click.
Reply

Use magic Report

0

Threads

64

Posts

35.00

Credits

Newbie

Rank: 1

Credits
35.00

 China

Post time: 2020-1-6 09:57:01
| Show all posts
Page1 prev = (Page1) this.PreviousPage;
if (prev == null)
  throw new Exception ("1.aspx was not executed.");

TextBox txtboxOnPage1 = prev.TextBox1;


Among them, Page1 is the type defined in your 1.aspx code behind code.
Reply

Use magic Report

7

Threads

15

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

 Author| Post time: 2020-1-6 11:12:01
| Show all posts
And VB syntax? I didn't understand the above
Thank you
Reply

Use magic Report

0

Threads

21

Posts

12.00

Credits

Newbie

Rank: 1

Credits
12.00

 China

Post time: 2020-1-6 11:15:01
| Show all posts
default.aspx

    Protected Sub Button1_Click (ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        TextBox1.Text = "hello wyp"
    End Sub

Result.aspx
 Protected Sub Page_Load (ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim prvPage As Page = Page.PreviousPage
        Response.Write (CType (prvPage.FindControl ("textbox1"), TextBox) .Text)
    End Sub
Reply

Use magic Report

7

Threads

15

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

 Author| Post time: 2020-1-6 13:15:01
| Show all posts
OK thanks
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list