No Postback Just Open Another Page

A

Art Cabot

ASP.NET Newbie Question:
I have buttons (<asp:button) on my page that I want to just open another
page (including some arguments from the original page), just like would
normally happen with the "action=" on a form. I can't seem to get it to stop
posting back, the HTML source always shows "action=original page", regardless
of what page I set the "action =" to.

Am I missing something really obvious here?
 
K

Ken Cox [Microsoft MVP]

Hi Art,

An ASP.NET page always posts back to itself, so that's the issue you're
encountering. Setting the action page doesn't help.

Try this to pass a value from one control to a second page:

1. Create a new page called btntrsfr.aspx and drop a Button and Textbox on
it.
2. Use the following code for Button1's Click event:

Private Sub Button1_Click _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Context.Items("txtValue") = TextBox1.Text
Server.Transfer("targetpg.aspx")
End Sub

3. Create the target page called targetpg.aspx .
4. Add a label control to the page.
5. Use the following code for the page's Load event:

Label1.Text = CType(Context.Items("txtValue"), String)

You should be able to type something in the text of btntrsfr.aspx, click the
button and see the text show up in the label of targetpg.aspx.

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]
Toronto
 
M

Mohamed El Ashmawy

Hello Art,
Please note that you can still use the HTML controls as <input
type="button" onclick=""> and you can set the action of the form then
submit to the new page.
This is more like a workaround but it will achieve what you want.

Regards
Mohamed El Ashmawy
MEA Developer Support Center
ITWorx on behalf of Microsoft EMEA GTSC
 
A

Art Cabot

Thanks, Ken. It works great!

Art


Ken Cox said:
Hi Art,

An ASP.NET page always posts back to itself, so that's the issue you're
encountering. Setting the action page doesn't help.

Try this to pass a value from one control to a second page:

1. Create a new page called btntrsfr.aspx and drop a Button and Textbox on
it.
2. Use the following code for Button1's Click event:

Private Sub Button1_Click _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Context.Items("txtValue") = TextBox1.Text
Server.Transfer("targetpg.aspx")
End Sub

3. Create the target page called targetpg.aspx .
4. Add a label control to the page.
5. Use the following code for the page's Load event:

Label1.Text = CType(Context.Items("txtValue"), String)

You should be able to type something in the text of btntrsfr.aspx, click the
button and see the text show up in the label of targetpg.aspx.

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]
Toronto
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top