Post back cotrol - asp.net-2.0

How to get the control or control Id which caused the post back in asp.net 2.0 page

There is a collection:
Request.Form
That is passed back to form. So iterating through keys you obtain name of controls. But these names matches Control.UniqueId, but not Control.ID

Related

How to pass more than one value in QueryString and how to retrieve it in other form

How I can pass more than two value and how I can retrieve it again in different page and also in same page. If I retrieve in same page and perform operation like delete, how can I do that?

Saving a selected value in gridview to viewstate

I am trying to capture and save the selected value in a gridview to a variable in viewstate which i would like to use to pass as a query string parameter to a differant page
Where would i save the ViewState Variable and how?
Iam very new and not usre whether i have provided enough information
Thanks
Values stored in ViewState work differently than session. Unlike Session, a value stored in ViewState of one page cannot be retrieved from another. Actually ViewState is nothing but a system managed hidden encrypted field in the markup produced. How do you save a value in ViewState? like this:
ViewState["MyValue"]=GrideView1.SelectedValue.ToString();
Later you can retrieve that value like this
if(ViewState["MyValue"]!=null)
{
Response.Redirect("SecondPage.aspx?param="+ViewState["MyValue"]);
}

asp.net 1.1 duplicated submission entries

I've got an old framework 1.1 project with the following problem: if user submits a page then in database duplicated records might appear. This error repeats often but is not consistent: in most cases there are no duplicated entries but in some cases there can be upto 4 of them. We disable submit button with JavaScript after first submission.
May be this would be helpful: there is a session object used to store user inputs (which are submitted).
Any scenarios you can think of why duplicated records can happen?
Many thanks
Finally I found that some mobile browsers ignored JavaScript that disabled submission button and users managed to resubmit form multiple times.
The easiest (?) solution to this is the following:
Create a table "SubmissionTokens" in database with two fields: Token (uniqueidentifier), DateCreated (DateTime). Then, when page with submission form loads, add a token to database and save "id" value in a hidden field on the same page. When user submits the form then read token from the hidden field and see if token exists in table SubmissionTokens. If it does exist then insert a new record with form data in the database and delete the token from SubmissionTokens. You can also use DateCreate field to expire tokens.
At work I implemented a bit different solution and just look for duplicated records in the database before inserting a new record. But this is because there is a specific requirement that user must be able to resubmit form if he clicks "back" in browser. In this case the SubmissionToken is already deleted and the first solution wouldn't work.

Get all textboxes' values in a form in MVC3?

I have a form tha contains a TreeView with many Textboxes in each node. the TreeView created dynamically with Razor and I don't know the name or ID of textboxes.
How can I get the value and id of all textboxes in the controller in MVC3 ?
I would use the FormCollection class. Read about it here http://msdn.microsoft.com/en-us/library/system.web.mvc.formcollection.aspx
In your controller;
Public ActionResult ActionName(FormCollection formCollection){
}
This allows you to gain access to any of the keys posted.
Request.Form.AllKeys will allow you to access all the fields in the form's ids. Then you can use Request.Form[id] to access the value.
Edit: Possible Dupe:How can I get all element values from Request.Form without specifying exactly which one with .GetValues(“ElementIdName”)

Keep ASP.NET ViewState without being passed via QueryString

I have a form with its method being "get" that passes the variables and their values to the query string, respectively. However, it also passes the viewstate variable in the query string. Now, I have a very long viewstate value on the given page, and if passed in the query string, the viewstate variable will cause the page to error out, due to "too long of a query string" which happens to also be too long of a url.
I cannot merely remove the viewstate variable - I need it. But I need to pass the viewstate variable along via some method other than get when the form is submitted, while the other inputs of the form (the non-hidden inputs) are appended to the query string. Is there any way to accomplish this?
Can you change the method to "post" and then use request.form to get your variables?
Otherwise, you might be able to use the session object...
...or a serializable class object
...or a temp table in a database
Several different options

Resources