Avatar of Kyle Abrahams
Kyle AbrahamsFlag for United States of America asked on

.Net Post form

Hi All,


I'm trying to update my hidden form items and then post to another page all in a single click.

So  I have a really simple form I have:
<input type="hidden" name="key" ID="key" runat="server" />

 and in a button click I do:
  key.Value = ConfigurationManager.AppSettings["Key"].ToString();


If I let the page come back and use another button with a postbackURL . . . the behavior works as expected.

If I try a response.Redirect the new value can't be read.
I cannot use a server.transfer as I'm going to a 3rd party site to submit the data.
I also tried the postback url on this button click as well, but that also can't be done.

So how do I update the value on the form and post it to another page?  Thanks in advnaced, been a long day and the brain is shot.
ASP.NETC#

Avatar of undefined
Last Comment
Kyle Abrahams

8/22/2022 - Mon
guru_sami

Response.Redirect won't work. You might want to try using other methods like saving in Session/ querystring parameter or cookie or db.
You can check CrossPage Posting.

You can access ConfigurationManager.AppSettings["Key"].ToString(); on other page as well. Not sure if you have is just an example or real code.
ASKER
Kyle Abrahams

Hi Sami,

Unfortunately I'm going to an external 3rd party website for credit card processing, so accessing the variables in the other page is a no go (or I would have thrown it in the session or something).   I have this working where if the first button just formats the variables and the second one submits the form it's working, but I don't want to rely on the users clicking 2 buttons.  

My goal now is to combine the 2 button clicks.

<!-- sets the key and other pertinent info -->
<asp:Button runat="server" ID="btnSubmit" Text="Submit" onclick="btnSubmit_Click"    />

<!-- no code behind, just a redirect -->
<asp:Button runat="server" ID="btnTransfer3rdParty" Text="CC Proccessing" UseSubmitBehavior="true" PostBackUrl="GATEWAY URL" />



I've also tried from the btnSubmit but this also doesn't work.
            string script = string.Format("window.open('{0}');", "GATEWAY URL");
            ScriptManager.RegisterStartupScript(this.Page, typeof(Page), "openSesame", script, true);


I need the values to be updated before going to the other page.
ASKER CERTIFIED SOLUTION
Kyle Abrahams

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
Kyle Abrahams

Solved.
Your help has saved me hundreds of hours of internet surfing.
fblack61