Storing user input in classic asp - asp-classic

What i have to create is a form that i migrated out of access. I created the 4 asp pages. Now what they would like is to store the user input values some how until they hit the final page before writing to the SQL database. What is the easiest way to store this data until the final page for submission? I could try an array or maybe even java script?

You could use the session object - http://msdn.microsoft.com/en-us/library/ms525095(v=vs.90).aspx

As suggested in this other answer, you could use session variables. The alternative is to just pass them from page to page using hidden form fields, eg
<input name="yourvariable" type="hidden" value="<%=Request.Form("yourvariable")%>
There's no correct answer, it's a case of which you're most comfortable with

"get_user_info.asp"
<html>
<head></head>
<body>
<form id='frm_user_info' name='frm_user_info' method='post' action='get_user_info_go.asp'>
<table cellspacing='3'>
<tr>
<td align=right>Name</td>
<td><input type='text' id='s_name' name='s_name' size='40'></td>
</tr>
<tr>
<td></td>
<td><input type='submit' value='Next'></td>
</tr>
</table>
</form>
</body>
</html>
"get_user_info_go.asp"
<%
s_name=request.form("s_name")
if (s_name="") then response.redirect("get_user_info.asp")
session("s_name")=s_name
response.redirect("next_page.asp")
%>

Related

ASP VB Script / Dreamweaver Clickable Results Link

I am building a document catalogue in Dreamweaver CS6 using asp VB Script and Access as my DB. I have a "documents" table with attributes of
-refid (PK) .........(this is an auto#)
-docname ...........(Description of the doc)
-location ..............(e.g. "images\Power Point\Smart-Wireless-Overview-16x9.pptx")
-typeid (FK).......(e.g. Manual, Presentation, Drawing etc)
-modelcode.........(e.g. 3051S, 3144 etc)
I am building a search field where the user can enter a search criteria and the system should display the document.
I was able to design the search and get accurate results however I am unable to get a clickable link for the user to view or download the document. All that is appearing on the browser is the actual link stored in the DB.
Is there any way for me to get a link or icon for the user to click to view the document?
------SEARCH CODE------
<h2>Select A Search Criteria</h2>
<div id="search_options">
<form name="form1" method="post" action="Result.asp">
<label for="input"></label>
<input type="text" name="input" id="input">
<input type="submit" name="search_btn" id="search_btn" value="Submit">
</form>
</div>
------RESULTS CODE------
<h2>Content Found</h2>
<div id="results">Content for id "results" Goes Here
<% If Not Search.EOF Or Not Search.BOF Then %>
<table border="1">
<tr>
<td>refid</td>
<td>docname</td>
<td>location</td>
<td>typeid</td>
<td>modelcode</td>
<td>Details</td>
</tr>
<% While ((Repeat1__numRows <> 0) AND (NOT Search.EOF)) %>
<tr>
<td><%=(Search.Fields.Item("refid").Value)%></td>
<td><%=(Search.Fields.Item("docname").Value)%></td>
<td><%=(Search.Fields.Item("location").Value)%></td>
<td><%=(Search.Fields.Item("typeid").Value)%></td>
<td><%=(Search.Fields.Item("modelcode").Value)%></td>
<td> View</td>
</tr>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
Search.MoveNext()
Wend
%>
</table>
<% End If ' end Not Search.EOF Or NOT Search.BOF %>
</div>
</section>
-----DETAILS CODE-----
<p>Content for id "results" Goes Here</p>
<p><img src="images/Data_Sheets/00813-0100-4001.pdf" width="82" height="73" longdesc="<%=(Details.Fields.Item("location").Value)%>"></p>
<p><%=(Details.Fields.Item("location").Value)%></p>
</div>
</section>

How to a use a web user control more than one time on the same page?

I have created web user control for calendar. I.e it has a textbox and a calendar image. By clicking on calendar popup the calendar opens. Then by selecting any date it stores the year of that date. I use this code:
<script language="javaScript" type="text/javascript" src="Scripts/Calendar.js"> </script>
<link href="Styles/Calendar.css" rel="stylesheet" type="text/css" />
<table>
<tr>
<td>
<input type="text" name="datum1"/>
</td>
<td>
<img id="Img1" src="images/calFinal.jpg" alt="" runat="server" onclick="setYears(1947, 2040);
showCalender(this, 'datum1');" />
</td>
</tr>
</table>
<div>
<!-- Calender Script -->
<table id="calenderTable">
<tbody id="calenderTableHead">
<tr>
<td colspan="4" align="center">
<select onchange="showCalenderBody(createCalender(document.getElementById('selectYear').value,
this.selectedIndex, false));" id="selectMonth">
<option value="0">Jan</option>
<option value="1">Feb</option>
<option value="2">Mar</option>
<option value="3">Apr</option>
<option value="4">May</option>
<option value="5">Jun</option>
<option value="6">Jul</option>
<option value="7">Aug</option>
<option value="8">Sep</option>
<option value="9">Oct</option>
<option value="10">Nov</option>
<option value="11">Dec</option>
</select>
</td>
<td colspan="2" align="center">
<select onchange="showCalenderBody(createCalender(this.value,
document.getElementById('selectMonth').selectedIndex, false));" id="selectYear">
</select>
</td>
<td align="center">
<font color="#003333" size="+1">X</font>
</td>
</tr>
</tbody>
<tbody id="calenderTableDays">
<tr style="">
<td>Sun</td>
<td>Mon</td>
<td>Tue</td>
<td>Wed</td>
<td>Thu</td>
<td>Fri</td>
<td>Sat</td>
</tr>
</tbody>
<tbody id="calender">
</tbody>
</table>
<!-- End Calender Script -->
</div>
The problem occurs when I use the user control twice on the same web form. I have registered the control. When I use it once, it works proper. But I want it at two places. So, please give some solution on how to use the user control more than one time on the same web form. I have given different IDs for the user control, but it still does not work.
Code for user control:
<tr>
<td class="directorytdWidth directorylabel">
School Name:
</td>
<td class="directoryTdPadding">
<asp:TextBox ID="txtSchoolName" runat="server" Width="120px" ForeColor="#FF9F00"></asp:TextBox>
</td>
</tr>
<tr>
<td class="directorytdWidth directorylabel">
School Passout Year:
</td>
<td class="directoryTdPadding">
<uc1:calendar ID="schoolPassout" runat="server" />
</td>
</tr>
<tr>
<td class="directorytdWidth directorylabel">
College Name:
</td>
<td class="directoryTdPadding">
<asp:TextBox ID="txtCollegeName" runat="server" Width="120px" ForeColor="#FF9F00"></asp:TextBox>
</td>
</tr>
<tr>
<td class="directorytdWidth directorylabel">
College Passout Year:
</td>
<td class="directoryTdPadding">
<uc1:calendar ID="collegePassout" runat="server" />
</td>
</tr>
Use the Same User control but With diferent ID. For example (See code below)
Reg Your User control in you Web page
<%# Register Src="~/Controls/SearchAffiliated.ascx" TagPrefix="uc" TagName="SearchAffiliated" %>
First User Control call
<uc:SearchAffiliated runat="server" ID="ucSearchAffiliated" />
Second User Control Call
<uc:SearchAffiliated runat="server" ID="SearchAffiliated1" />
See The Users Controls have diferents IDs, That Works For call The same UC in one web form.
Cheers.
Use the loop of how many times that u want the usercontrol to display:
for(int i=0;i < n; i++) //Define the number of time that u want to display
{
usercontrolname.id="UC"+i;//Assign the id for that usercontrol
//add line of code,that controls in placeholder or panel
}
You can use same user control in same page in N number of times. either it dynamically or statically. Only the thing is we need to give the different ID for the usercontrol
This need to add in your Reg
<%# Register Src="~/UserControls/Hello.ascx" TagPrefix="uc" TagName="Hello" %>
calling the user control 1
<uc:Hello runat="server" ID="ucHello1" />
calling the user control 2
<uc:Hello runat="server" ID="ucHello2" />
I faced same problem but the problem was not related with the ID you prefer to use inside the asp.net page. Because I guess asp.net automatically generates ID for each element in page if it doesn't have one.
The problem was I copied ascx files and forget to change their class names. Make sure you use different class names for each user control.
<%# Control Language="C#" ClassName="ucSchema2" %>
I know this i late to the game but maybe someone can use this answer anyway.
Using a static clientside id for a html element in a user control and then using that user control multiple times will results in invalid html.
You are only allowed to use an id once on a html page otherwise getElementById (which returns a single element) will not know which element to get and then you will probably not get any element whatsoever.
You need to make those clientside ids inside the user control truely unique, i.e. selectMonth, selectYear.
This might be done by appending the ClientID of the user control to the element id. Something like this (not sure if this approach really works but you get the idea):
<select onchange="showCalenderBody(createCalender(document.getElementById('selectYear_<%=this.ClientID%>').value,
this.selectedIndex, false));" id="selectMonth_<%=this.ClientID%>">
This way the clientside id should be a combination of locally unique ids and the page unique control ids.

Spring MVC Binding: How to find if bind action was successful

I have a Spring MVC form:select whose form:options are bind with a List<Custom_Object>. The List<Custom_Object> is named as LOCALIZATION_LIST in the code below.
The path attribute of form:select is used to set the selected option.
<form:form action="editNode.do" method="post" name="editNodeForm" commandName="editElementDetails">
<table>
<tr>
<td>Data Type</td>
<td>
<form:select path="datatype" onchange="" cssClass="large" id="datatypes">
<c:if test="${! empty LOCALIZATION_LIST}">
<form:options items="${LOCALIZATION_LIST}" itemLabel="local_Name" itemValue="local_Name"/>
</c:if>
</form:select>
</td>
</tr>
</table>
</form:form>
Now my problem is that there might be a scenario when editElementDetails.datatype may contain a value which is not there in LOCALIZATION_LIST at all. So currently Spring MVC shows the first element of LOCALIZATION_LIST as selected.
Is there a way I can figure out whether the bind action for setting the selected object in form:options of form:select was successful or not?
So that when the binding was not successful, I can then add one extra form:option with the new value in the form.
Note: Answering my own question
I figured it out for now by manually searching for the incoming command object field value in the LOCALIZATION_LIST and if not found, adding an extra form:option corresponding to it.
I was hoping to find a JSTL/Spring-MVC out-of-box solution for this though.
Here is the code:
<form:form action="editNode.do" method="post" name="editNodeForm" commandName="editElementDetails">
<table>
<tr>
<td>Data Type</td>
<td>
<form:select path="datatype" onchange="" cssClass="large" id="datatypes">
<c:if test="${! empty LOCALIZATION_LIST}">
<c:set var="contains" value="false" />
<c:forEach var="item" items="${LOCALIZATION_LIST}">
<c:if test="${item eq editElementDetails.datatype}">
<c:set var="contains" value="true" />
</c:if>
</c:forEach>
<c:if test="${ !contains }">
<form:option label="${editElementDetails.datatype}" value="${editElementDetails.datatype}"/>
</c:if>
<form:options items="${LOCALIZATION_LIST}" itemLabel="local_Name" itemValue="local_Name"/>
</c:if>
</form:select>
</td>
</tr>
</table>
</form:form>
What you want to achieve is the process of validating a form submission that is what I understood (maybe got you all wrong).You can use Spring-Validator here is one nice tutorial about using it.
Spring Form validation . Hope this helps.

How does MVC Client Side validation work exactly?

I have used MVC MVC 2.0 Client Side validation, but it does not work as expected. Now I am trying to find out, what I did wrong.
How does it work?
I have this rendered form:
<form method="post" action="/Sprint/Edit/68d4886b-a86a-4f0b-b713-39219febddf3">
<fieldset>
<legend>Sprint</legend>
<table>
<tbody><tr>
<td><label for="sprint_Title">Title</label></td>
<td><input type="text" value="Wichtige Private Erledigungen" name="sprint.Title" id="sprint_Title" class="input-box t-input"></td>
<td><span class="error"><span id="sprint_Title_validationMessage" class="field-validation-valid"></span></span></td>
</tr>
<tr>
<td><label for="sprint_Date">Date</label></td>
<td>
<div id="sprint_Date" class="date-picker t-input t-widget t-datepicker"><input value="12.05.2010" name="sprint.Date" id="sprint_Date-input" class="t-input" autocomplete="off"><a title="Open the calendar" tabindex="-1" href="#" class="t-link t-icon t-icon-calendar">select date</a></div>
</td>
<td><span class="error"><span id="sprint_Date_validationMessage" class="field-validation-valid"></span></span></td>
</tr>
<tr>
<td><label for="sprint_Description">Description</label></td>
<td><textarea rows="10" name="sprint.Description" id="sprint_Description" cols="80" class="t-input">dsfs1</textarea></td>
<td><span class="error"><span id="sprint_Description_validationMessage" class="field-validation-valid"></span></span></td>
</tr>
</tbody></table>
</fieldset>
<input type="submit" value="Submit" name="Submit" id="Submit" class="t-button t-state-default">
</form>
And this script is rendered:
<script type="text/javascript">
//<![CDATA[
if (!window.mvcClientValidationMetadata) { window.mvcClientValidationMetadata = []; }
window.mvcClientValidationMetadata.push({"Fields":[{"FieldName":"sprint.Title","ReplaceValidationMessageContents":true,"ValidationMessageId":"sprint_Title_validationMessage","ValidationRules":[{"ErrorMessage":"Title is required.","ValidationParameters":{},"ValidationType":"required"}]},{"FieldName":"sprint.Date","ReplaceValidationMessageContents":true,"ValidationMessageId":"sprint_Date_validationMessage","ValidationRules":[{"ErrorMessage":"Das Feld \"Date\" ist erforderlich.","ValidationParameters":{},"ValidationType":"required"}]},{"FieldName":"sprint.Description","ReplaceValidationMessageContents":true,"ValidationMessageId":"sprint_Description_validationMessage","ValidationRules":[]}],"FormId":null,"ReplaceValidationSummary":false});
//]]>
</script>
But to my surprise the breakpoint only stops at page load. I think it should be also if a field is tabbed? At least, after I press the post button.
Why does client side validation not work for me?
This just sets up the handlers, it won't actually hit this line when the form is submitted, nor when you tab between fields.
You will get validation errors upon losing focus and/or form submission, however if you have other javascript errors on the page it can cause this to fail.
Also, make sure you've reference the required javascript files in your header:
MicrosoftAjax.js
MicrosoftMvcValidation.js

ASP.NET MVC displaying user Data such as comments?

hows the best way to display comments/user data from a db using mvc?
do we just do our own for loop and manually display it or? will doing it this way cause paging problems in the future? any best methods or practice?
jquery?
thanks guys.
When I first started learning MVC, I put a lot of conditional code in the view to manage the display of the data and controls. However, once I figured out the benefit of HTML helpers, I found that it not only reduced the code in my views, but it also made it easier to test the resulting output.
As an example, this is a code fragment for an entry form that would appear in the finished HTML page:
<table class="listing">
<tr>
<td class="prompt">Last Name:</td>
<td><input id="LastName" name="LastName" value="Smith" /></td>
</tr>
<tr>
<td class="prompt">First Name:</td>
<td><input id="FirstName" name="FirstName" value="John" /></td>
</tr>
<tr>
<td class="prompt">Job Title:</td>
<td><input id="JobTitle" name="JobTitle" value="Manager" /></td>
</tr>
</table>
Building the view using standard MVC helpers would result in code that looks something like this:
<table class="listing">
<tr>
<td class="prompt">Last Name:</td>
<td><%= Html.TextBox("LastName", Model.LastName) %></td>
</tr>
<tr>
<td class="prompt">First Name:</td>
<td><%= Html.TextBox("FirstName", Model.FirstName) %></td>
</tr>
<tr>
<td class="prompt">Job Title:</td>
<td><%= Html.TextBox("JobTitle", Model.JobTitle) %></td>
</tr>
</table>
However, I was able to create HTML helpers that allowed me to make the view look like this:
<table class="listing">
<%= Html.Edit_LastName(Model.LastName) %>
<%= Html.Edit_FirstName(Model.FirstName) %>
<%= Html.Edit_JobTitle(Model.JobTitle) %>
</table>
Here are the HTML helpers:
private string Edit_Field(string prompt, string fieldName, string value)
{
string textBox = helper.TextBox(fieldName, value);
return string.Format("<tr><td class='prompt'>{0}</td><td>{1}</td></tr>", prompt, textBox);
}
public string Edit_LastName(this HtmlHelper helper, string value)
{
return EditField("Last Name:", "LastName", value);
}
public string Edit_FirstName(this HtmlHelper helper, string value)
{
return EditField("First Name:", "FirstName", value);
}
public string Edit_JobTitle(this HtmlHelper helper, string value)
{
return EditField("Job Title:", "JobTitle", value);
}
This method is not nearly as straightforward as the standard method, but if you have similar controls that are used on multiple views, this approach clearly helps with maintenance. For example, if you want to change the prompt text from "Job Title" to "Position", you just change the prompt string in the Edit_JobTitle method and the change is reflected in every view where that method is called.
is the best way to use client jquery
with tablesorter or server side for
loop?
I don't think there is a connection between these two. Anyways you have to use an iterator to get all the rows from the database. Then you can use jQuery plugin to view the data in pages.
Here is a nice implementation of this
Table Sorting, Paging and Filtering with jQuery
IMO, use the iterator. I use jquery plugins when I need a display format that is complex. jquery itslef is useful when you need to access/modify dom or make ajax calls. Paging shouldn't affect this decision or vice-versa.

Resources