Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 23rd, 2009, 10:45 AM
Authorized User
 
Join Date: Oct 2006
Posts: 20
Thanks: 1
Thanked 0 Times in 0 Posts
Default Submitting a form with a hidden variable

This is probably a simple question but I have spent the last 2 hours on it and keep going down blind alleys.

I have an existing asp.net app which I wrote 2 years ago and I now need to add a page containing a form that invokes an external application using https. In my initial testing I got the basics to work using the following (slightly simplified ) code:

<form name="moduleForm" action="https://www.securesite..."
method="post" enctype="multipart/form-data" target="_blank" >
<input type="hidden" name="username" value="P128">
<input type="hidden" name="password" value="xxx">
<input type="image" src="../Statements.gif" hspace="5" name="memberstatements" />
</form>

I now need to dynamically update the hidden variable "username" with the actual username, which I have stored in a Session variable. I've tried several things, converting the form to runat=server and creating a Page_Load, etc. but the code is getting messier and I keep bumping into gotchas. The latest is that forms post unto themselves (didn't remember that). There must be a simple way to update this one variable and then let the user click on the button to submit the form.

(Sorry but my brain is in Coldfusion mode and I just can't get it back to .Net!!)
 
Old May 23rd, 2009, 02:02 PM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

Have you considered using an HiddenField server control then doing a crosspost?
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
 
Old May 23rd, 2009, 05:09 PM
Authorized User
 
Join Date: Oct 2006
Posts: 20
Thanks: 1
Thanked 0 Times in 0 Posts
Default

That's probably part of a solution that would work. But my understanding is that if I use any input control that is marked runat="server", then I must also do the same with the form. And then it will always postback to itself. So then I assume I'll have to write some routine (perhaps an onclick) to actually call the new application. Feels like a lot of extra work to me.

For what it's worth I reverted to old ASP here and inserted the following into the page code right in the middle of the form. It took me one line and it worked:

<%
Response.Write( "<input type='hidden' name='username' value='" & Session("Account") & "'>" )
%>
 
Old May 23rd, 2009, 05:17 PM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

Quote:
Originally Posted by jpullam View Post
That's probably part of a solution that would work. But my understanding is that if I use any input control that is marked runat="server", then I must also do the same with the form. And then it will always postback to itself.
Server forms do not have to post back to themselves. They can post to any form you want. That's what I meant by doing a crosspost.

Anyway, you got it working, so that's all that matters I guess.
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}





Similar Threads
Thread Thread Starter Forum Replies Last Post
Submitting a form to a database nvillare Classic ASP Basics 2 January 27th, 2005 06:38 PM
form submitting cro_crx Pro PHP 5 January 25th, 2005 12:19 PM
Form Submitting cro_crx Beginning PHP 3 January 17th, 2005 01:30 PM
Submitting a form YuliaKupina Classic ASP Basics 3 June 24th, 2004 01:52 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.