How to prefill a form with post data in ASP.NET - c#

I need to populate a form in the main page which on being submitted opens a lightbox which contains another form .
I was planning to submit the form using Post as that seems to be the only way I can define which iframe to open in the lightbox .However my question is that how do I pre-populate the second form with the first forms data when I use the submission as POST
I am using ASP.NET and C#
I apologize for the naive question but I am still playing around with ASP.NET

We dont have many details on items such as - is there a redirect? whats the second form? how are you handling controls.. etc
Check this out to start. If you really need to send values across separate requests there are various ways to do this, but specify if this is what you are trying to do.
http://msdn.microsoft.com/en-us/library/ms178139.aspx

Use the Form collection in the Request object on the second form. The name in the collection is the same as the name in the name/value pair you're using in the post.
TextBox1.Text = Request.Form["someName1"];
TextBox2.Text = Request.Form["someName2"];
Etc.

Related

Showing and posting in separated actions in a main view

I would like to explain my scenary: I have a form that is composed by 2 other partial views.
The idea is the following
The main Form show details about a Budget.
The second show a form to send messages.
The third show a form to send offer bids;
I would like that, when I do a Post in the 2nd ot 3rd form, the application return the main form. but, it is returning the form that was Posted.
It would work like I was using IFRAME... in other words, when I do a Post, it reflect only in the form that was Posted.
I am doing this form with MVC in C#.
Any tip?
I tried to use [ChildActionOnly], but I suppose that isn't what I am looking for.
If I understand your problem correctly,you must use "return View("MainView");" instead "return View();"
The right Answer is:
I created a new View;
I changed the strucure Html.Beginform to Ajax.BeginForm;
Used the jqueryunobtrusive.
You can see an example here: enter link description here

Url Hiding in MVC

Can any one please help me out.
How to manage the url in the address bar,which will not to be changed for every operation in certain controller(create/Edit/Delete like ).
for Example if we are in page like 'http://localhost/Music'
when we are adding we will get 'http://localhost/Music/Add'
but when editing the particular item details 'http://localhost/Music/Edit?id=XXXXXXX'
here, I want to display the url Every time as "http://localhost/Music/ " only,How ?
You will need to use AJAX if you want the user to stay on the same page all the time. So basically you will not be performing full postbacks but only asynchronous AJAX calls.
You could use the Ajax.* helpers or implement this functionality yourself using for example jQuery.ajax.

maintain viewstate for html elements?

I have a generic 'form page' user control that we use that allows editors to insert whatever kind of html form they want to inside of it, and it handles all of the form posts.
My question is, is there a way to store the vanilla non-asp form entries in the viewstate or otherwise save the entries on a form post, in the case that some server-side validation fails, so they can be restored when the page refreshes?
We currently already do upfront javascript validation that catches the majority of the input errors. We store all the form post data in a db before we do further processing, and some of the entries contain junk (spam we wish to ignore) or only partial info (i'm assuming those are cases where the user doesn't have javascript enabled). I'm trying to catch these last fringe cases so we do not process them.
If I am understanding this correctly,
1>User fills form
2>Clicks submit
3>Error detected on the server side
4>The Html posted back should contain the form i already filled with an error message on top.
Have you considered using JQuery Ajax?
The jquery ajax will post to a web method. The web method returns a JSON response. If the response is success redirect user to the next page, else show error on top of the page.
That way you don't need to maintain the state of the user input (since it is never lost).
If you dont know what the form fields are ahead of time then I would reccomend that you look into partial postbacks.
Or else post the forms via ajax.
you could store the text HTML in
<asp:HiddenField ID="hid1" runat="server" />
this will be passed in View State

Using jQuery with ASP.NET to Submit a Form

I've used jQuery dozens of times with PHP with great success. I'm working on an ASP.NET application and would like to use jQuery in the same manner.
Basically, I've got a masterpage that has the form and a webform that has all the form fields and data. A user can submit the form multiple ways - selection of a drop-down, button, etc. I want to catch all submits and use jQuery to submit the form. While the form is being processed, I want to display a new DIV with some text in it. Finally, I want to replace that div with the new form.
How can I accomplish this with the way that ASP.NET works?
Actually ASP.NET will post-back if you use its built-in JavaScript __doPostBack function. There's no other painless way for doing that.
That means you can use jQuery to handle drop-down lists, buttons or whatever (X)HTML element event and handler's body will invoke __doPostBack.
It's unclear that you want is a full-postback, but a partial one using AJAX.
If you're looking for a solution for sending form values to the server without a full-postback, I believe you've these options:
Callback API: http://msdn.microsoft.com/en-us/library/ms178208.aspx
Page methods, update panels: http://msdn.microsoft.com/en-us/magazine/cc163480.aspx
Anyway, let me give you an advise: ASP.NET works quite different compared to PHP and you'd not try to reproduce some known PHP solutions in ASP.NET. You need to change your mind.
About showing a DIV or anything while something is processed, play with initializeRequest ASP.NET AJAX PageRequestManager:
http://msdn.microsoft.com/en-us/library/bb397460.aspx
But that would depend on what AJAX API you're using, because since Microsoft AJAX will be replaced by jQuery in the next times, I'll need to say that you need to do that in some jQuery approach, like creating some $.ajax wrapper so your code will be able to listen when an asynchronous request is going to be made and you can perform actions by handling that situation like showing a DIV or any loading notice.
In ASP.NET Webforms formposts aren't as easy as they are in php. If you're new in ASP.NET development try http://www.asp.net/mvc. A common framework which allows you to implement TypedViews (ViewModes), simple request to modelbinding, and so on...
mh, sample:
[HttpPost]
public JsonResult Insert(string name, string vorname) // name&vorname filled by $_POST:)
{
var #new = new Person { Name = name, Vorname = vorname }
this.repo.Insert(#new);
return this.Json(new { success = true, newId = #new.Id });
}

Pre-populate a SharePoint new item form

I need to pre-populate a list form (the add new item form for a list)
with some details (the logged in users name and email address)
how can i do it?
2 options:
create your own custom form with controls.
create a tiny weppart that does nothing else but render user info in javascript. then use jquery to get that info in the fields in the form.
I'm doing the same thing, trying to populate a people picker field.
I'm not done yet, but I was able to implement a CEWP (Custom Editor Web Part) in the form, adding:
?PageView=Shared&ToolPaneView=2
at the end of the URL of the new form. Example:
NewForm.aspx?RootFolder=.....default.aspx**&PageView=Shared&ToolPaneView=2**
After that,I put JQuery in the Web Part content, until now I trying to implement SPFF, but is kinda hard because there are not too many examples... by the time I'm done I would be pleased to help you

Categories

Resources