Adding to cookie file via Button using Classic ASP - button

I'm making a website for pictures and am trying to use cookies for the shoppingcart.
Is it possible to add data to a cookie via a buttonclick?
This is my code:
<?
Response.Cookies ("MYCOOKIE").Expires = DateTime.Now.AddDays(5)
Response.Cookies ("MYCOOKIE")[("BgColor")] = "Kibbeling 26 : Sea Warrior's Strike Back "
Response.Cookies ("MYCOOKIE")("Date") = DateTime.Now
Dim MyCookie
Dim MyCookie2
MyCookie = Request.Cookies ("MYCOOKIE")("BgColor")
MyCookie2 = Request.Cookies ("MYCOOKIE")("Date")
Response.Write(MyCookie)
Response.Write(MyCookie2)
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Cookies</title>
</head>
<body runat="server" id="BodyTag">
</body>
</html>

Related

Data Not Filtering in Jquery Autocomplete

I've followed the examples http://jqueryui.com/autocomplete/
but instead of a fixed array I wanted a dynamic array from a database
I've almost got it working but as I type it won't filter the results and even if I type a letter that doesnt exist in the array, it still shows the full list.
search.asp
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery UI Autocomplete - Default functionality</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.0/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script>
<script>
$(function() {
$("#tags").autocomplete({
source: 'http://fullurl/autocomplete.asp'
});
});
</script>
</head>
<body>
<div class="ui-widget">
<label for="tags">Tags: </label>
<input id="tags">
</div>
autocomplete.asp
<%
sConn = "DRIVER={MySQL ODBC 5.1 Driver}; SERVER=SERVER; Port=3306; DATABASE=database; UID=username;PASSWORD=password; OPTION=3"
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open sConn
sSQL = "SELECT * FROM makes ORDER BY makes ASC;"
Set rst = Server.CreateObject("ADODB.Recordset")
rst.CursorLocation = 3
rst.Open sSQL, Conn, 3, 1
output = "["
DO Until rst.EOF
output = output & chr(34) & rst("makes") & chr(34) & ","
rst.movenext
Loop
output = left(output,(len(output)-1))
output = output & "]"
Response.Write output
rst.close
Conn.Close
%>
This is the result of autocomplete.asp: ["ACER","DELL","HP","LENOVO","SONY"]
any ideas what I've done wrong or missed out
Changed Jquery to the follow and works fine now
<script>
$(function() {
$.getJSON("autocomplete.asp", function(data) {
$("#tags").autocomplete({
source: data
});
});
});
</script>

Validate XHTML frameset

I am trying to validate my XHTML Frameset page but I get the following errors from the W3C Markup Validation Service:
Missing "charset" attribute for "text/xml" document.
Line 1, Column 41: parsing XML declaration: '?>' expected
I have the following heading in my file:
<?xml version = "1.0" encoding = "utf-8" charset=utf-8?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">
I changed the heading as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
I added the following meta tag in between the head tags:
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
No more errors or warnings.

ASP.NET MVC Dynamic Stylesheets

The project I'm working on allows an end-user to modify CSS code to integrate the application as best possible. Most of the CSS values are stored in a database and need to be retrieved and parsed dynamically.
I setup a Style controller, and gave each stylesheet an action, and then passed the configuration data through to the View. I set the ContentType to "text/css" and then generated the stylesheets.
This works fine, but the problem I'm running into is this: none of the code works in the application. I include it in the head code, but it doesn't parse in the code.
An example of what I do is this:
<%# Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" ContentType="text/css" %>
.element {
background-color: <%= ViewData.Model.BackgroundColor %>;
}
I include it like so:
<link href="/style/Basic" rel="stylesheet" type="text/css" media="all" />
When I include the CSS code in a partial view and include it using the ViewModel (wrapped in style tags) in an action, then everything works fine. It is when I try to parse this as a separate file when it does not work.
Is there something I am doing incorrectly? Or is there some kind of glitch?
Thanks in advance :D
Use a tool such as HTTPWatch to verify that the stylesheet is being sent down and not 404'd
Controller
public ActionResult Basic()
{
Response.ContentType = "text/css";
var basicVM = new BasicVM()
{
BackgroundColor = "Lime",
};
return View(basicVM);
}
And the View
<%# Page Language="C#" Inherits="System.Web.Mvc.ViewPage<MvcApplication3.Controllers.BasicVM>" ContentType="text/css" %>
body {
background-color: <%= ViewData.Model.BackgroundColor %>;
}
and the test page
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Test</title>
<link href="/Home/Basic" rel="stylesheet" type="text/css" media="all" />
</head>
<body>
<div>
Test
</div>
</body>
</html>
Turns everything Green

Any Asp.net or Asp.net MVC template based system?

Is there any template based system available for .net? I have several domains i want to handle them using a single system. Each domain can have different design. But all will be manage through a single management system.
Assuming that you mean that you want your app to select it's CSS and images folder dynamically based on the host name (domain name) in the request in order to skin your app based on the domain name, you could try something like this:
public static class Skin
{
public static string Url(string assetPath)
{
var host = System.Web.HttpContext.Current.Request.Url.Host;
switch (host)
{
case "www.myfirstsite.com":
return UrlPath("~/Content/myfirst/" + assetPath.TrimStart('/'));
case "www.theothersite.com/":
return UrlPath("~/Content/theother/" + assetPath.TrimStart('/'));
default:
return UrlPath("~/Content/default/" + assetPath.TrimStart('/'));
}
}
private static string UrlPath(string virtualPath)
{
return VirtualPathUtility.ToAbsolute(virtualPath);
}
}
Which would make all your views look something like this when referencing CSS and images:
<%# Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>My Page</title>
<link rel="stylesheet" type="text/css" href="<%= Skin.Url("css/master.css") %>" />
</head>
<body>
<img src="<%= Skin.Url("images/myimg.gif") %>" alt="myimg" />
</body>
</html>

Adding 2 HTMLGenericControl script with src attribute not working

I have asp.net 2.0 c# application.
I have 2 scripts I want to add to a user control's control collection. Instead of adding them one after another, it only opens one script tag and throws the 2 src strings together as strings
string tagLinks = "/Resources/Javascript/js/taglinks.js";
HtmlGenericControl scriptTagLinks = new HtmlGenericControl("script");
scriptTagLinks.Attributes["type"] = "text/javascript";
scriptTagLinks.Attributes["src"] = tagLinks;
this.Controls.Add(scriptTagLinks);
script = new HtmlGenericControl("script");
script.Attributes.Add("type", "text/javascript");
script.Attributes.Add("src", gsJSHost);
this.Controls.Add(script);
This is what happens:
<script type="text/javascript">/Resources/Javascript/js/taglinks.jsvar pageTracker =
_gat._getTracker('UA-1213766-27'); pageTracker._initData();pageTracker._trackPageview();</script>
Here is what I've found out about your answer:
I added (basically) your code to my user control loaded event (which will inject the script tags that you're looking for). I don't have the global script that is contained in your gsJSHost global variable so I substituted with the variable name.
This is my control code:
Public Partial Class MyControl
Inherits System.Web.UI.UserControl
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim tagLinks As String = "/Resources/Javascript/js/taglinks.js"
Dim scriptTagLinks As HtmlGenericControl = New HtmlGenericControl("script")
scriptTagLinks.Attributes.Add("type", "text/javascript")
scriptTagLinks.Attributes.Add("src", tagLinks)
Me.Controls.Add(scriptTagLinks)
Dim script As New HtmlGenericControl("script")
script.Attributes.Add("type", "text/javascript")
script.Attributes.Add("src", "gsJSHost")
Me.Controls.Add(script)
End Sub
End Class
This is my resulting page source:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>
</title></head>
<body>
<form name="form1" method="post" action="Default.aspx" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUIMTI2NzczMzlkZE8ExRatvhvKqmX5DtpWJX8MhAcE" />
</div>
<div>
<script type="text/javascript" src="/Resources/Javascript/js/taglinks.js"></script><script type="text/javascript" src="gsJSHost"></script>
</div>
</form>
</body>
</html>
Please download the source code at my Google code demo project:
http://code.google.com/p/stackoverflow-answers-by-scott/
Direct link to zipped download:
http://stackoverflow-answers-by-scott.googlecode.com/files/1716701.zip
I hope this helps,
Thanks!

Resources