How do i use two Images (as buttons) within one form (asp classic) - asp-classic

I have a form within a repeating region that I would like to have two buttons on.
I currently have one button (an image) that submits the form and generates a preview of the record. I would like to add a second button to the same form that performs a different function. I have assigned different names and values to each of the image buttons but how do I retrieve that value and either do a corresponding response.redirect or perform an additional function?
I know in PHP you can use the $_GET["getvar"]; or $_post["getvar"]; but i am using classic asp.
Any help would be greatly appreciated!

example for you
<input type="hidden" name="PageAction" value="" />
<input type="image" name="button1" src="imgage1.jpg" onclick="this.form.PageAction.value='function1';this.form.submit();" />
<input type="image" name="button2" src="imgage2.jpg" onclick="this.form.PageAction.value='function2';this.form.submit();" />
then you can retrive the value of request("PageAction") to seperate diffrent actions,like:
if request("PageAction")="function1" then
call function1()
elseif request("PageAction")="function2" then
call function2()
end if

Request.QueryString("getvar") is the equivalent of $_get and Request.Form("getvar") is the equivalent of $_post.
Where getvar is the name of the button, it will return the value.

Related

Vue.js: insert value into textfield but don't bind it

I am facing an interesting problem: I have a form where I want to insert old values (if the form was submitted before) like this:
<input type="text" :value="oldName" id="name" />
Now the problem is that I can't overwrite the oldName variable like this, so yes, I have the old value in there, but I can't change it anymore. Can you think of a solution? I basically want the value to be in the textfield, but I want the user to be able to change it. Thank you!
Sounds like adding v-once to the input field would solve your problem. V-once means that oldName will be used to render the value once, but after that it will be a normal string literal.
<input type="text" :value="oldName" id="name" v-once/>
In case you want the user to be able to modify the value use v-model instead of v-bind. V-model provides two way binding so when the user writes something in the input field it is reflected in the value.
<input type="text" v-model="oldName" id="name" v-once/>

ASP.NET: Can I read the ViewState to restore a control in the client site?

I am curious: is it possible to read the initial state of a DropDownList control using JavaScript?
Let’s say that when the page is loaded in the browser, the dropdown has ten options. Then, using JavaScript I remove all the options.
Can I read the ASP.NET ViewState to get the initial ten options and restore them?
The short answer is yes you can use JavaScript to read the viewstate values as they are stored in a field called __viewstate, which is rendered in the browser as an input field like this:
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="..." />
The problem you will run into is the __viewstate value is encrypted.
My suggestion is to use a hidden field to store the values of the dropdown or whatever else you want to store and then access the value like this:
<input type="hidden" id="hiddenField" runat="server" value="" />
Then in your code-behind, since the input has the runat="server" you can set the value to whatever you wish, like this:
hiddenField.Value= ViewState["dropdownvalues"].ToString();
Finally, you can use JavaScript to get the values from the hidden field, like this:
<script type="text/javascript">
function test()
{
var name = document.getElementById('hiddenField').value;
alert(name)
}
</script>

What happens to an "input" on "submit"? And how can that be done by ASP.Net? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Read Post Data submitted to ASP.Net Form
I have a google checkout "buy now" button, and am trying to add dynamically created content to send when it's clicked. Using the original html is proving a bit difficult so I want to create an ASP.Net ImageButton Instead of that.
I've succeeded in creating the button with the right image, and hooking it up to an event handler in the codebehind.
However, I'm not sure what exactly happens when the original button is clicked, in order to try and emulate it in the new ImageButton.
The original code is:
<form action="https://sandbox.google.com/checkout/..." id="Form1" method="post" name="..." target="_top">
<input name="item_name_1" type="hidden" value="..." />
...
<input alt="" src="https://sandbox.google.com/checkout/buttons/buy.gif?merchant_id=..." type="image" />
</form>
And I want to place a dynamically created item_name_1.
What do I have to do in the Button1_Click method for that?
The short, concise and usefull version:
Html:
<form id="__parent" action="..." method="post" runat="server">
<input id="__child0" name="type" type="hidden" value="button" runat="server" />
<input id="__child1" name="name" type="hidden" value="teh_button" runat="server" />
<input id="__child2" name="value" type="hidden" value="Hello?" runat="server" />
</form>
tehfile.cs:
<%# Page Language="C#" CodeFile="tehfile.cs" %>
String
_type = __child0.Value,
_name = __child1.Value,
_value = __child2.Value,
_element = String.Format(
"<{0} {1}=\"{2}\" {3}=\"{4}\" {5}=\"{6}\" />",
"input",
"type", _type,
"name", _name,
"value", _value );
Literal _lit = new Literal( );
_lit.Text = _element;
__parent.AddControl( _lit );
To post that data to another server on the ASP.NET server-side, you are going to need to use something like the WebRequest class.
Or also in order to post a form, you can use a remote post class like any of the ones here: Remote HTTP Post with C# , the answer by #BobbyShaftoe is the one i've used in many projects.
Same question/POST here. I would have commented instead of answered, but seems this is a better/formatted way to get to bottom of it all:
In your comment to #MarcusHansson's answer:
I fail to see how this addresses the question of how to use the codebehind to send the information
You are mixing server side with client side submission methods.
If you want to submit using "code behind" you must implement server-to-server HTTP Post. In the context of Google Checkout, I've provided that link in your other post.
Your client side is using an HTML FORM which in, and of itself is how you "send the data". You can try all sorts of client-side submission processes, but at the end of the day, it is a client-side (Javascript) method.
What is "dynamic" about your buy now button? It's meant for a single item (at a time) purchase. Why can't you construct all the variables you need at the same time you create the button? What are you adding (that requires another redirect or postback)?

ASP.Net using multiple form tag and post them to another page

I don't know it's even possible but I try to achieve to post data from one page to another using the second form.
The problem is I need a form tag for the user interface containing callback panels etc. I want to put a second form with some hidden-field:
<form id="postForm" method="post" action="target.aspx">
<input type="hidden" id="id" />
</form>
I submit the form from javascript with jquery:
$("#id").val(id);
$("#postForm").submit();
Is there a way access the value of the hidden field on the target page?
You should give the hidden field a name attribute:
<input type="hidden" id="id" name="id" />
You'll then be able to use Request.Form in your target page to access the posted data:
string postedId = Request.Form["id"];

Dealing with checkboxlists and radiobuttonlists when POSTing forms

What is the right way of creating and processing a group of related controls on posted forms?
From using ASP.NET MVC I see a standard option is to create a number of inputs and assign the same "name" attribute value to them. Like this:
<input name="OrderOptions" type="checkbox" value="1" />
<input name="OrderOptions" type="checkbox" value="2" />
...
<input name="OrderOptions" type="checkbox" value="N" />
And when processing forms we get all the values in a comma delimited string:
public OrderController
{
public ActionResult (FormCollection form)
{
string selection = form["OrderOptions"];
}
}
Now, is this how it is supposed to be done with any server technology? Does assigning the same name value to inputs break some validation rules or something?
One extra question: If I were to use the built-in HTML helpers, I would get the inputs generated with both "id" and "name" attribute. Like this:
<input id="OrderOptions" name="OrderOptions" type="checkbox" value="1" />
<input id="OrderOptions" name="OrderOptions" type="checkbox" value="2" />
...
<input id="OrderOptions" name="OrderOptions" type="checkbox" value="N" />
But it is clearly invalid to have multiple elements with the same "id" in a document. Still, it works.
If I discard the standard helpers and make my own, do I need to insert the "id" attribute to inputs if I do not really need it (except in some label cases)? Some folks are telling we have to always assign both "id" and "name" attributes to elements because there is some incompatibility with old browsers, and the "name" attribute is deprecated (I know it is only for some other elements). But even if I wanted to, I would have to assign different id/name values for input elements and then I cannot process them as a group. You see my dilemma?
Any advice is greatly appreciated.
a) No. Assigning the same name is definitely valid behaviour -- it's how radio buttons know which group they're a part of (so that others in the same group turn off when you click one, while other groups on the same page are unaffected).
b) Yes, having the same ID is invalid. I have the same problem with the helper apps. It makes the entire page invalid and, for me at least, makes any javascript more difficult.
No, you don't need the ID. But if they exist they should be unique. Furthermore, I don't know about this whole "name being deprecated" thing. How else will forms work? Forms do not submit the ID when POSTing back. See http://www.w3.org/TR/html401/interact/forms.html#edef-INPUT .
If you choose to assign ID, they can be different without affecting group_processing. In fact, I'll generally name them something like "OrderOptions-<%= order.option.id %>".
EDIT:
PS: Use the html validator at http://validator.w3.org/#validate_by_uri+with_options . It'll catch and notify you of things like duplicate IDs or missing IDs. It'll also (if I remember correctly) tell you of deprecated elements/attributes that you use.
James

Resources