MVC :: Form Values Not Appear Afret Post?
Jan 24, 2011i have the same problem like http://forums.asp.net/t/1645052.aspxMODEL
public class StudentModel
{
public int StudentID { get; set; }
[code]...
i have the same problem like http://forums.asp.net/t/1645052.aspxMODEL
public class StudentModel
{
public int StudentID { get; set; }
[code]...
See what happens when you answer my questions! I come back! No good deed goes unpunished. I've built an Update form where my visitor can update data in dbase. I have a formview with several dropdown lists; none of which will update the table (all the textboxes, checkboxes and even Ajax enabled calendar work just fine). In the form below, visitor selects a CareerCluster from the ddl. Upon postback, the next ddl (pathwayListBox) populates with related data using the CareerCluster.selectedvalue in a query. At the same time, tsaOrgsDropDownList is also populated based upon the first ddl (CareerCluster).
When user selects from the tsaOrgsDropDownList the final ddl (tsaDropDownList) is populated. All this various selecting/populating works just fine on the form. The problem is: Nothing is updated to the table upon clicking the Update button. All other form fields do post as their supposed to except, I have other ddls on the page that are not related to the above series and they won't post either. My thought is that somehow, this is related to the postbacking going on. That posting back is overwriting the selectedValues with null or something.
<asp:FormView ID="courseUpdateFormView" runat="server" BackColor="White" BorderColor="White" BorderStyle="Ridge" BorderWidth="2px" CellPadding="3" CellSpacing="1" DataKeyNames="CTECourseID" DataSourceID="formviewSqlDataSource" Width="715px">
<FooterStyle BackColor="#C6C3C6" ForeColor="Black" />
<RowStyle BackColor="#DEDFDE" ForeColor="Black" />
<EditItemTemplate>
<table align="center" width="700" border="1" cellpadding="10" cellspacing="2" bgcolor="White">
<%--A whole bunch of textboxes goes here--%>
<tr>
<td bgcolor="#dadada">
<strong>Number of HS Credits:</strong> <span>(Standards-based districts use the <em>Other</em> form field.)</span>
</td>
<td bgcolor="#FCCCCC">
<span><font color="red">Note: you must reselect HS Credits from the list or enter Other credits in the form field provided.</font></span><br />
<asp:DropDownList ID="numHSCreditsDropDownList" runat="server" TabIndex="3" ToolTip="Standards Based districts us the Other form field." ValidationGroup="HSCredits" AppendDataBoundItems="True" OnSelectedIndexChanged="numHSCreditsDropDownList_SelectedIndexChanged">
<asp:ListItem Selected="True" Value="0">--Choose One--</asp:ListItem>
<asp:ListItem>0.5</asp:ListItem>
<asp:ListItem>1.0</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td bgcolor="#dadada">
<strong>Career Cluster:</strong>
</td>
<td bgcolor="#FCCCCC">
<span><font color="red">Note: you must reselect Career Cluster from the list.</font></span><br />
<asp:DropDownList ID="careerCluster" runat="server" AutoPostBack="True" TabIndex="4">
<asp:ListItem Selected="True" Value="0">--Choose One--</asp:ListItem>
<asp:ListItem Value="1">Agriculture, Food & Natural Resources</asp:ListItem>
<asp:ListItem Value="2">Architecture & Construction</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td bgcolor="#dadada">
<strong>Pathways:</strong> <span>(Pathway as defined in the Cluster/Pathway model.)</span>
</td>
<td bgcolor="#FCCCCC">
<span><font color="red">Note: you must reselect Course Pathway from the list or enter Other Pathway in the form field provided.</font></span><br />
<asp:ListBox ID="pathwayListBox" runat="server" DataSourceID="CTECourses" DataTextField="ClusterPathway" DataValueField="ClusterPathway" SelectionMode="Multiple" Style="margin-left: 0px" TabIndex="5" Rows="3">
<asp:ListItem Selected="True" Value="0">--Choose One--</asp:ListItem>
</asp:ListBox>
<asp:SqlDataSource ID="CTECourses" runat="server" ConnectionString="<%$ ConnectionStrings:CareerTechEducationConnectionString %>" SelectCommand="SELECT [ClusterName], [ClusterPathwayID], [ClusterPathway], [ClusterCode] FROM [lkClustersPathways]
WHERE ([ClusterCode] = @ClusterCode)">
<SelectParameters>
<asp:ControlParameter ControlID="careerCluster" Name="ClusterCode" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</td>
</tr>
<tr>
<td align="center" bgcolor="#4A3C8C" colspan="2">
<asp:Label ID="occupationalStandardsLabel" runat="server" Font-Bold="True" ForeColor="White" Text="Occupational Standards"></asp:Label>
</td>
</tr>
<tr>
<td bgcolor="#dadada">
<strong>Source of Occupational Standards:</strong>
</td>
<td bgcolor="#FCCCCC">
<span><font color="red">Note: you must reselect Source of Occupational Standards from the list or enter Other Source of Occupational Standards in the form field provided.</font></span><br />
<asp:DropDownList ID="tsaOrgsDropDownList" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource3" DataTextField="TSAOrganization" DataValueField="TSAOrgID">
<asp:ListItem Selected="True">--Choose One--</asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:CareerTechEducationConnectionString %>" SelectCommand="SELECT [TSAOrgID], [TSAOrganization] FROM [lkTSAOrgs] WHERE ([TSAClusterID] = @TSAClusterID)">
<SelectParameters>
<asp:ControlParameter ControlID="careerCluster" Name="TSAClusterID" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</td>
</tr>
<%--A whole bunch of textboxes, checkboxes and other stuff goes here--%>
<tr>
<td bgcolor="#dadada">
<strong>What is the Summative Assessment (Technical Skills Assessment) for this course:?</strong>
</td>
<td bgcolor="#FCCCCC">
<span><font color="red">Note: you must reselect Summative Assessment from the list or enter Other Summative Assessment in the form field provided.</font></span><br />
<asp:DropDownList ID="tsaDropDownList" runat="server" AutoPostBack="false" DataSourceID="TSAs" DataTextField="TSA" DataValueField="TSAID" Width="300">
</asp:DropDownList>
<asp:SqlDataSource ID="TSAs" runat="server" ConnectionString="<%$ ConnectionStrings:CareerTechEducationConnectionString %>" SelectCommand="SELECT [TSAID], [TSA] FROM [lkTSAs] WHERE ([TSAOrgID] = @TSAOrgID)">
<SelectParameters>
<asp:ControlParameter ControlID="tsaOrgsDropDownList" Name="TSAOrgID" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</td>
</tr>
<%--A whole bunch of textboxes goes here--%>
<tr>
<td align="center" bgcolor="#dadada">
<asp:Button ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="Update" />
<br />
<span><font color="maroon">* All fields except the Tech Prep Information are required.</font></span></div>
</td>
<td align="center" bgcolor="#dadada">
<asp:Button ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</td>
</tr>
</tr>
</table>
</EditItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="formviewSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:CareerTechEducationConnectionString %>" SelectCommand="SELECT * FROM tblCTECourses WHERE (CTECourseID = @CTECourseID)" UpdateCommand="UPDATE tblCTECourses
SET HSCredits = @HSCredits, CareerCluster = @CareerCluster, Pathways = @Pathways, TSAOrgs = @TSAOrgs, TSA = @TSA, LastUpdate = GETDATE() WHERE (CTECourseID = @CTECourseID)">
<SelectParameters>
<asp:SessionParameter Name="CTECourseID" SessionField="CTECourseID" Type="Int32" />
</SelectParameters>
<UpdateParameters>
<asp:FormParameter FormField="numHSCreditsDropDownList" Name="HSCredits" Type="String" />
<asp:FormParameter FormField="HSCreditsOtherTextBox" Name="HSCreditsOther" Type="String" />
<asp:FormParameter FormField="careerCluster" Name="CareerCluster" Type="Int32" />
<asp:FormParameter FormField="pathwayListBox" Name="Pathways" Type="String" />
<asp:FormParameter FormField="tsaOrgsDropDownList" Name="TSAOrgs" Type="Int32" />
<asp:FormParameter FormField="tsaDropDownList" Name="TSA" Type="String" />
<asp:FormParameter FormField="TSAOtherTextBox" Name="TSAOther" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
In the codebehind I've tried to set selectedvalue to session variable upon selected index changed like this:
Protected Sub numHSCreditsDropDownList_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
Session("HSCredit") = DirectCast(courseUpdateFormView.FindControl("numHSCreditsDropDownList"), DropDownList).SelectedValue
End Sub
Is there a way to force a non-secure form post to be secure? I understand there are ways to automatically resolve an http URL as an https URL but with form posts, is this type of redirection too late? Will the posted data have already gone through the wire as plain text?
View 3 RepliesI have Master Page and ascx user controls in my application.
how would I use the Cross-Page technique using the @ PreviousPageType directive.
useful links or samples to achieve this.
I am trying to use the Page class that exposes a property named PreviousPage from my User Control.
I was told to use a Repeater control in what I am doing which is a "Data Entry" screen with ASP.NET controls -a standard "address" like form. In cases, the fields on the form will repeated twice, once for the original values, one for the changed values. I have not used this control before but it seems like I have to bind to a database. Instead, I have an Entity object that has been obtained via a Repository. Can I bind to an object like this?
[DataContract()]
public class RON
{
[code]...
I need to delete all the item what I seleted or I Checked.so I collect all the ID I selected .
then what should I do next?I could not find a submit button to send them,they are not in a from.So I try to collect them to a JSON object and then use AJAX to send them to server.
How to carry values from "Form to Form" in ASP.net using vb.net?
View 2 RepliesI have two asp.net applications webapp1 and webapp2, in each application i have a asp.net form Deafult.aspx
I want to do a form submit from Default.aspx in webapp1 and recieve the value in webapp2.
I tried to do it with simply setting action ="webapp2 location" but it is throwing the bellow error
Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.
I even added the machinekey element to web.config
but it is still showing the same error.
This is the code for webapp1 form which sends data to webapp2
[Code]....
Our problem is the following:
We have a website that processing products from various web shops! Users of these web shops can send products for our site what will store these products in our database. Users are sending in products through the post method of the form, and within the form the data is in hidden imput fields! Our site using UTF-8 charset, and this service is working like a charm together with other pages that has utf8 chaset too. The problem comes when someone using our service from a site that has other charset then utf8, for example: iso-8859-2.This case the special hungarian characters, like "íéáűőúöüó" are replaced with a '�' character!We have tried to convert the incoming string on server side but that case the '�' has been replaced by '?'. - still not acceptable :)
Why is it not possible to post my form from an iframe? The form in the iframe is the same as the form outside the iframe. I have put in the EnvableEvent Validation="true". It is not working.
View 6 RepliesUsing Facebox with .NET (Web Forms) is painful--this primarily HTML site was designed by someone else. I may have IIS (7.5) issues as well. This Facebox pop-up is in a separate file, login.html, that is called from index.html:
$k('a[rel*=example_2]').facebox_1({
loading_image : '/images/loading.gif',
close_image : '/images/closelabel.gif'
});
and the link to open it
<a href="login.html" title="Log In" rel="example_2" id='login'>Log In </a>
The form to be submitted with username and password (login.html):
<form name="login" method="post" action="#" onsubmit="return false;">
and after it's validated (this is working), it posts to login.aspx (login.html):
[code]....
The form posts. I can debug it in Visual Studio in the Page_Load method of login.aspx. The last line of the Page_Load method is:
Response.Redirect("welcomepage.html");
But, the Facebox pop-up remains. Firebug shows the post, It hits the Page_Load method of login.aspx, and the Facebox pop-up doesn't go anywhere. BUT, Firebug shows welcomepage.html rendered twice in the Response tab of the XHR (huh? why XHR?) request. I thought $.post did a regular postback. And why isn't my browser actually redirecting.
Attempted Fix
If I change the form in login.html to action='login.aspx', I get a 405.0 error method not allowed (but, it's trying to post to index.html, HUH?). And I can't figure out how to fix this in IIS 7.5 on Windows 7. I get this error in Visual Studio and when deploying locally to IIS. I had read it may have to do with script mapping, handlers, or the fact that I'm posting from an but I can't find a sufficient fix.
I am trying out ASP.NET MVC2. I have a controller called SearchController and a view folder called Search containing Search.aspx. In my controller I have:
[code]....
In my view I have:
<form action="Search/Post" method="post">
<label><% Response.Write(Model.Title); %></label>
<input type="Submit" Value="First" Name="submitButton"/>
</form>
It works fine the first time I click the button, and the browser shows a url of [URL]. However, when I click the button a second time the browser url changes to [URL] and I get a 404. What am I doing wrong?
I want to be able to post my form data to another page based on the result of a validation done on server (and not via javascript). As an example, let's say the user captures a customer number and then captures the phone number of the customer on page A. When the user clicks on the submit button, the page posts back. Then, in the button click event, I need to check in the database if the customer number exists. If it exists, I need to post the data to page B so that user can input the next information. If it does not, I need to stay on the first page and show an error message telling the user that the customer does not exists.
I do not want to use Response.Redirect cause that would mean that page B would lose the form data coming from page A. I know about crosspage postbacks but that just turn the problem the other way around (if I post directly to page B, how do I get back to page A with the form data and show the error message?)...I know about Server.Transfer too but I would like to avoid that method because I know there are down sides to it too...I tried setting the button target URL to page B after validating from the database but it does not automatically redirect to Page B, it still shows up Page A and then if you click again on the button you are taken to page B. I know I could setup a javascript to automatically call the click on the button to post the page the second time automatically to the Page B but I don't like that method (if the user has slow internet, he sees the page twice and once the user is on page B, he can't use the back button cause he would be automatically redirected back to Page B because of the script).So, is there a way to change the request target after the button's click code has been handled???
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?
I have a single model type to wrap up various models I want to use in my view:
public class QuestionViewData {
public Question Question { get; set; }
public IList<Answer> Answers { get; set; }
}
Now, in my question view I pull the data from the Question object - that's fine. Secondly I iterate through all Answer objects and pass them to a partial view:
<% foreach(Answer item in Model.Answers) { %>
<% Html.RenderPartial("ShowAnswer", item); %>
<% } %>
For each answer (in the partial view) I have some action buttons (like ratings). I'm using separate form POST's with hidden fields for every button. The problem is that I can't post the whole QuestionViewData model to my action method cause I only have the Answer object as model in the partial view. However, I need to return the complete question view from that action that takes QuestionViewData as model.
I am trying to simulate a POST to a form on an external server that does not require any authentication, and capture a sting containing the resulting page. This is what the form looks like:
<FORM METHOD="POST" ACTION="/controller" NAME="GIN">
<INPUT type="hidden" name="JSPName" value="GIN">
Field1:
<INPUT type="text" name="Field1" size="30"
maxlength="60" class="txtNormal" value="">
</FORM>
This is what my code looks like:
ASCIIEncoding encoding = new ASCIIEncoding();
string postData = "Field1=VALUE1&JSPName=GIN";
byte[] data = encoding.GetBytes(postData);
// Prepare web request...
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("https://XXX/controller");
myRequest.Method = "POST";
myRequest.ContentType = "text/html";
myRequest.ContentLength = data.Length;
Stream newStream = myRequest.GetRequestStream();
// Send the data.
newStream.Write(data, 0, data.Length);
StreamReader reader = new StreamReader(newStream);
string text = reader.ReadToEnd();
MessageBox.Show(text);
newStream.Close();
Currently, the code returns "Stream was not readable".
I don't know how to retrieve a DropDownListFor value on form post and how to validate it.
This is my scenario:
HTML markup:
[Code]....
Model:
[Code]....
I'm not able to validate this dorpdown and when I test if the Model is valid I have to re-fill the Location property
[Code]....
otherwise I get an "object reference not set" error on post-back.
I have done much searching and tried capturing javascript keydown events and such but cannot seem to stop a form from posting upon the user typing the ENTER key. I am using VB with VS 2008 SP1 and .NET 3.5 SP1. However, the ENTER key should function properly within a textarea input. So I have refrained from placing the keydown event in the Body tag.So I have wired up keydown events in 6 <asp:textboxes> that use the AutoComplete Extender. The javascript called is:
function on_keydown(e) {
var keynum;
var keychar;
var numcheck;
[code]...
I have a View that has a select drop-down list and an edit button within a form. What I want to do is have the user select one of the options from the select element, click on the edit button, and get the value of the selected option in the Controller method.
I created my form with <% Html.BeginForm(): %>
and the Controller "Edit" method should be called.
I looked through several online examples, but each one focused on how to set values and the default selected value of the select element, rather than retrieving it from the code in the Controller method. I tried grabbing it from the Request.Form collection like:
string val = Request.Form["myDropDownList"].ToString();
and also:
string val = Request.Form["myDropDownList"];
Obviously I didn't do this correctly, because I get a null reference exception. Does anyone have the solution to this issue?
Hope this is the right forum to ask. I am trying to write a simple mobile application with two form fields that POST to a webservice that queries an SQL database and comes back with an XML file that needs to be parsed and displayed
properly in a browser.
So what I have is a webservice .asmx file that is working properly and an HTML form that POST two variables to the webservice file. The result is the generated XML. I simply just need to know the simplest way to display parts of that data as output within the
design of the form page.
Here is the HTML form: http://www.bt4u.org/
And here is the web service: http://www.bt4u.org/BT4U/BT4U_WebService.asmx
If you enter in the following respectively you will see the XML file:
MSS-1607
HWD-2104
there is some sort of class that stores the XML in an array or some such thing that can then be manipulated
I need to know how to post information from an HTML <form> to a page that's within an IFRAME on an external server. In other words, the page with the <form> is on the first server, page being posted to is on the second server within an IFRAME which is also on the second server.
I've seen snippets of code for posting to a page within an IFRAME, but I believe that these apply to an IFRAME and target page on the same server as the posting page.
I have to submit a form to authorizenet with the information in hidden fields. I'd like to do this on a postback button click as I have to validate the form first.
View 3 Repliesi m facing this problem for sum time now, and not found a solution yet.here it goes i have a webform on on which i have certain input fields,and a button trick here is i also want this form to connect to a payment gateway so i want this form to post some values to payment gateway, so on button click first it shouldsave the date and then post values and redirect user to payment gateway, during my tries i found out, it will only do one of the two if i specify form actiona and form method it will not save the data but directly redirect,which is not correct,i want both things to happen saving as well as post to payment gateway
View 9 RepliesI notice on some sites i can login wrong which brings me to a login page. log in incorrectly again which brings me to a wrong password page (where i can log in) and if i login wrong again i dont increase my page history count. It takes exactly 2 backs no matter how many times i get it wrong and i dont see any pages in my forward history
View 3 Repliespublic class BandProfileModel
{
public BandModel Band { get; set; }
public IEnumerable<Relationship> Requests { get; set; }
}
and the following form:
<% using (Html.BeginForm()) { %>
<%: Html.EditorFor(m => m.Band) %>
<input type="submit" value="Save Band" />
<% } %>
which posts to the following action:
public ActionResult EditPost(BandProfileModel m, string band)
{
// stuff is done here, but m is null?
return View(m);
}
Basically, I only have one property on my model that is used in the form. The other property in BandProfleModel is just used in the UI for other data. I'm trying to update just the Band property, but for each post, the argument "m" is always null (specifically, the .Band property is null). It's posting just fine to the action, so it isn't a problem with my route. Just the data is null.
The ID and name attributes of the fields are BAND_whatever and Band.whatever (whatever being a property of Band), so it seems like it would work. What am I doing wrong? How can I use just one property as part of a form, post back, and have values populated via the model binder for my BandProfileModel property in the action?