• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 285
  • Last Modified:

.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.
Kyle Abrahams
Kyle Abrahams
  • 3
1 Solution
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.
Kyle AbrahamsSenior .Net DeveloperAuthor Commented:
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.
Kyle AbrahamsSenior .Net DeveloperAuthor Commented:
I ended up calling the click for the second button in the first:

  string script = @"$(document).ready(function () { $(""#" + btnTransfer3rdParty.ClientID + @""").click() } );";
            ScriptManager.RegisterStartupScript(this.Page, typeof(Page), "openSesame", script, true);
Kyle AbrahamsSenior .Net DeveloperAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now