i have a problem
I have an A form with one with a hidden field that redirects to the other in a button.
In form B, i mus get the value of this hidden field by POST.
But when I do the Request.Form("Hidden_Field"), it only brings me the name of the field, when what I need is the VALUE.
any ideas?.
here is the code:
Form A:
<asp:HiddenField ID="SIGNSYS_OUTPUT" runat="server" Value="123" />
Server.Transfer("~/VerifyAccountBGBAResult.aspx", True)
Form B:
Me.Value = Request.Form("SIGNSYS_OUTPUT")
This Request returns me in the value "SIGNSYS_OUTPUT".
Server.Transfer does not transfer the information unless the form got posted first, I'll assume this is the case.
Request.Form gets the information based on the name of the control, example.
<input type="hidden" name="SIGNSYS_OUTPUT" value = "123" />
When you use runat="server" the name is generated by .net. You'll need to do a viewsource to get the proper name. It might end up being something like this.
Request.Form("ctl00$ContentPlaceHolder$SIGNSYS_OUTPUT")
In your case, I think using Server.Transfer might not be the best solution. You could look at other solution like using a session, the database, process on the page and send to result to the other page, ect..
Related
Previously i passed the parameters to my page in a query string. Now, how am i supposed to get them and use them in my page ?
I tried this code and it doesn't work :
<asp:Label runat="server" ID="ShowParameter"><%# Request.QueryString["IDProduct"] %></asp:Label>
You need to use <%= Request.QueryString["IDProduct"] %>. # is used for databinding.
It also goes without saying that you should also check to make sure the query string is not null and that it actually exists. It is also generally not a good idea to directly output a query string like this for a number of reasons.
I'm coming from Rails so I'm a little lost since this is my first time touching ASP.
I'm working on a legacy ASP app and I have a form in classic ASP and there are two inputs. How would I view and use the parameters so that I can use them to update my records? Are they stored in some sort of variable by default? And do I do this on the page of the form or the page after?
My input:
<input class="textboxsm" type="text" onkeypress="return numbersonly(window.event.keyCode,1)" onblur="poswarnings(1);updateTotals();" onfocus="rowfocus=0" value="2" maxlength="4" size="2" name="ia1" style="text-align:right;">
And this is the button that submits the form:
<input width="116" type="image" height="70" onmouseout="this.src='art/order_continue.gif'" onmouseup="this.src='art/order_continue.gif'" onmousedown="this.src='art/down_order_continue.gif'" onclick="return orderdone()" name="submitorder" alt="Done" src="art/order_continue.gif">
So how would I extract the value from my input?
Values sent via POST are stored in the Request.Forms collection. Items passed via query string are in the Request.QueryString collection.
Depending on your setup, you can access the values a number of different ways. Most commonly, people know what form fields to expect, so if you have:
<input type="text" name="Title" maxlength="200" size="90" />
Assuming your form method is POST, you would retrieve it on the page the form is posted to by:
strTitle = Request.Form("Title")
This does assume you have already defined strTitle, and the value is not null/empty/etc. and/or that you are checking for that later on...
You're pulling the value of the form item named "Title" from the Request.Form collection and assigning it to the variable strTitle (which should have been defined earlier) From there you can do whatever validation you need to do.
The only thing that would change if you were sending the request via GET instead of POST is you would use the Request.QueryString collection - like so:
strTitle = Request.QueryString("Title") 'Same assumption as before...
I have two HTML tables, the first one is populated on the server side through entries in the database, and the second is populated through client-side Javascript that allows the user to dynamically add rows and enter in data through input text boxes.
A button at the end of my form is responsible for committing the data from both to a SQL Server back end. The issue is on postback I am not able to read from these tables. This is the case for the client-side managed table, as well as the server sided managed table.
<table style="display: none; width: 100%" runat="server" id="tblWebOrderArbitraryContacts" class="borderBottomStyle">
<table runat="server" id="recipientTable" style="display: block; width: 100%" class="borderBottomStyle"></table>
//the problem is the row count is always zero, regardless of what data is in it
if(tblWebOrderArbitraryContacts.Rows != null && tblWebOrderArbitraryContacts.Rows.Count > 0)
{
//go through automatically derived (from integrations) contacts
foreach (HtmlTableRow row in tblWebOrderArbitraryContacts.Rows)
{
...
Explanation
The issue is that when a request is sent to the server for that page, a new instance of the page is created, along with all of the controls as defined within your .aspx file. This new instance of the page and child controls start out with no data.
When you submit a "post" request back to the server (a "Postback"), the page looks at the request's form collection (the data from <input> tags submitted by the browser) and attempts to update the web controls on the page with the data found within that form collection.
Also, but beside the point, viewstate aware controls may attempt to populate themselves based on data found in viewstate left behind by a different instance of the same control from a previous request.
Specifically, if you look at the TextBox webcontrol, you can see that it implements the IPostBackDataHandler interface. What happens is that during the beginning of the request, the page looks at all of the values in the form collection submitted by the request. When the page locates a value in the form collection whose key matches the ID of a TextBox control, the page is able to apply that updated value to that TextBox control using the LoadPostData method of the IPostBackDataHandler interface.
It sounds like what you're doing is add several rows of data to a table and post them all back to the server at one time. You can do this, but the problem is that there are no controls on your page that can act as targets for that data. Specifically, you need to be assigning the name attribute of your <input> tags in order for the data to be submitted to the server, but what would you put as the value of the name attribute? It's not going to match up to a control on your page. Furthermore, if you are submitting multiple rows at once, how would you distinguish one from the other?
Possible Solution
Assuming that your page, after javascript manipulation and user input, looks something like this:
<table>
<thead><tr></th>First Name</th><th>Last Name</th></tr></thead>
<tbody>
<tr><td><input name="FirstName[0]" value="John" /></td><td><input name="LastName[0]" value="Smith" /></td></tr>
<tr><td><input name="FirstName[1]" value="Jane" /></td><td><input name="LastName[1]" value="Doe" /></td></tr>
<tr><td><input name="FirstName[2]" value="Spider" /></td><td><input name="LastName[2]" value="Man" /></td></tr>
</tbody>
</table>
In your code-behind during the postback you can access that data using code such as the following:
string firstName = Request.Form["FirstName[0]"];
string lastName = Request.Form["LastName[0]"];
You could also do something like this:
int index = 0;
bool dataFound;
do
{
dataFound = false;
string firstName = Request.Form["FirstName["+index+"]"];
if (firstName != null)
dataFound = true;
string lastName = Request.Form["LastName["+index+"]"];
if (lastName != null)
dataFound = true;
// do something with firstName and lastName ...
index++;
} while (dataFound);
I believe the issue with your client side changes is that your table is not adding anything to the form’s post data. You are manipulating the markup on the client but the markup itself is not what posts back, just the input elements and their values are posted. Try adding a hidden input and recording the client side changes there so that the data gets posted back to the server. Then on the server side you can parse the contents of the input field to determine what changes were made.
I suspect that you have a similar issue with your table that is populated through server side code. If you are not storing a record of your changes to the declared markup somewhere (viewstate, session, etc.) then the server has no idea what was generated by the previous request and falls back on the declared markup.
Look at some of the articles about declaring controls dynamically for a deeper explanation. https://web.archive.org/web/20211020131055/https://www.4guysfromrolla.com/articles/081402-1.aspx#postadlink give a pretty good look into what is happening though the techniques and examples used are a bit dated.
I have 2 pages, one is HTML and the other is ASPX. In the HTML I am able to get input from a user and then process a return email to them.
The HTML looks like this:
<input type="text" class="input" value="e-mail" id="txtEmail" name="contactEmail" onclick="SelectAll('txtEmail');" >
and I'm using the following in the method
Dim sResponseToName As String = Request.Params("contactEmail").ToString
This part of my page works perfect as someone sends me a request I am about to direct an email to their "contactEmail"
However, in my aspx page it looks like this:
<asp:TextBox ID="contact_Email" CssClass="inputtext1" runat="server">
and the method used is:
Dim sResponseToName As String = Request.Params("contact_Email").ToString()
but no email is sent to the input email address.... If I hard code a random email instead of Request.Params("contact_Email").ToString() it works fine. But for some reason I can not get to the inputted user address.
kinda stumped, I've tried a few things but no luck. How do I get the Request.Params to work in an aspx, and do I need to add something in <asp:TextBox....> to reference it.
Please help, thanks in advance.
The beauty of making the asp:TextBox a server control is that, within the server code, you have access to the actual object. So there's no need to deal with the request parameters, you can just access the TextBox object:
Dim sResponseToName As String = contact_Email.Text
You have to reference the TextBox object like this:
Dim sResponseToName As String = contact_Email.Text
what is the best way of passing querystring to another page, i would definitly avoid like using.......
<a href="Page2.aspx?WONumber=12345">
is there any better way?
i was thinking create a Baseclass with few prop and update the baseclass?
thanks.
It sounds like you want to take the querystring argument, and use it in subsequent pages.
If it's not desirable to pass-forward this querystring argument from your current page, perhaps it's called page1.aspx, without using another querystring parameter, you could:
store the value in Session. Consider Session["WoNumber"] = Request.QueryString["WONumber"].ToString();
store the value in Cookies. You could use something like: Response.Cookies["WoNumber"].Value = Request.QueryString["WONumber"].ToString();
It really depends on where you're getting the value from. You can build a URL using UriBuilder or if it's simple enough string concatenation could be OK (though you'd have to make sure to Server.UrlEncode the values).
If the value is a constant, as your example implies, then there is nothing wrong with putting it directly into a query string, although I would still use a proper named constant, eg.
<a href="Page2.aspx?WONumber=<%= TheMagicOrderNumber %>
with the constant defined in the code-behind:
protected const int TheMagicOrderNumber = 12345
If your objection is the maintainability of "magic string" URLS, and you'd be prepared to use a button instead of an anchor, you could do worse than
<form method="GET" action="Page2.aspx">
<input type="hidden" name="WONumber" value="12345" />
<input type="submit" value="Navigate" />
</form>
this method will generalise to a query string of any complexity with any number of parameters.
There is a great article I came across a few months ago when I was looking for enhanced security with querystrings...
http://devcity.net/Articles/47/1/encrypt_querystring.aspx
It's a very good article, and has a bonus the author offers code examples in C# and VB.NET.
There are times when I prefer to use querystrings over sessions... small number of session objects is ok, but too many and it starts to become a bit tedious to debug problems.
You can encrypt a querystring parameter, if security is your concern.
Or you can use other holders, such s p.cambell says above (session & cookie).
You could also store it in a database, and have the page you go to retrieve it onload.
Just depends on your application requirements.
Another thing I've done is to use <asp:panel>, basically using a single page as though it were multiple pages. In this way, I also have access to viewstate to hold my variables. (Whenever a user clicks 'next', or whatever they would click to goto the next page, I simply hide the panel they're on, and show the panel they want to go to [visible = true/false] property)