Sunday, 2 June 2013

FIX: A potentially dangerous Request.Form value was detected from the client

If you are having a problem with using a wysiswyg editor for example then this can fix the "A potentially dangerous Request.Form value was detected from the client" error for a specific file/page, this is useful because you don't want to lose the layers of security provided to other pages. This should be put under in web.config. <location path="Admin/Pages/EditPage.aspx">
<system.web>
<httpRuntime requestValidationMode="2.0" />
<pages validateRequest="false" />
</system.web>
</location> Hopefully this will help

Thursday, 16 May 2013

Format Twitter Feed Create Date

Here's how to format the Twitter Date to the C# .net DateTime datatype. You will need to use "using System.Globalization;"

string date = [YourTwitterDateHere];

DateTime twitterDate = DateTime.ParseExact(date, "ddd MMM dd HH:mm:ss zzz yyyy", CultureInfo.InvariantCulture);

Why they have this format is beyond me, but this is how you can use it for what ever purpose you require in your project. Enjoy!

Wednesday, 15 May 2013

Twitter API 1.1 oAuth - Cut the crap and get it working :D

After lots of research, piecing together of all sorts of code, I finally managed to get a working version of oAuth API 1.1 in twitter. It still need a lot of refactoring, but you will get the idea. Its not pretty, but it works :D When I get time I might improve this and post a cleaner version ;) It turns out its is quite fussy about how you send the request with the request headers. This also uses JSON.net to parse the and dynamic type is quite interesting and is something I havent used before. This will allow you to databind to control like any other datasource which is useful and to return just the latest tweet you can literally just change the count to 1. Anyway enough waffle, you can download the source from: Download Sourcecode Or you can see the class below.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TwitterTest;

namespace TwitterControl
{
public partial class TwitterControl : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
// Setup Request
Twitter.ScreenName = "Test"; // This can be any twitter account
Twitter.Count = 20;

// These can be found in your developers seciton of twitter dev.twitter.com and in your applications
Twitter.oAuthConsumerKey = "";
Twitter.oAuthConsumerSecret = "";
Twitter.oAuth_token = "";

// Generate Random Base 64 Code
Twitter.oAuth_nonce = Twitter.generateNonce();

// Signature Method
Twitter.oAuth_signature_method = "HMAC-SHA1";

// Timestamp
Twitter.oAuth_timestamp = DateTime.Now.ToString();

// API Version
Twitter.oAuth_version = "1.1";

twitterRepeater.DataSource = Twitter.RetrieveTweets();
twitterRepeater.DataBind();
}
}
}

There is an issue with adding count, it has to be added to base string, in due course I will update this, its just finding the time :\

Thursday, 20 December 2012

AspxGridView ID Displaying Instead of Name/Description/Value

Well had a bit of problem with the id showing the dev express control AspxGridView. This was when binding GridViewDataComboBoxColumn, to fix this use the ensure you set the valuefieldto your id and textfield to description/name for example. Also when applying FieldName on the GridViewDataComboBoxColumn ensure it is not the same as your KeyFieldName on ASPxGridView Also it is worth noting that you should check the ordering that you are binding when using the GridViewDataComboBoxColumn as this can also cause display issues.

Monday, 29 October 2012

Halloween - Jquery, Animate, Top, Left, End of Animation

Here is a quick halloween example, this can obviously be improved, but should help out people get a basic understanding of how to repeat a jquery animation. This is a simple example with a tranparent ghost png.

<style>
body {
background::#000;
overflow-x: hidden;
overflow-y: scroll;
background-color: #000;
}

#ghost {
background:url(img/ghost.png) transparent;
height:128px;
width:128px;
position:absolute;
left:-128px;
overflow:hidden;
}
</style>

<script language="javascript" src="js/jquery-1.8.2.min.js"></script>

<script>

$(document).ready(function () {

function ghost(div){

$(div).css("left","-128px");

// Fading Start
$(div).fadeTo(5000, Math.random(), function() {
// Animation complete.
});
// Fading End

$(div).animate({
left: "+=" + ($("body").width() + 140),
top: (Math.ceil(Math.random()*500)),

},
5000,
function() {
var randomize = Math.ceil(Math.random() * 10000);
setTimeout(function() { ghost(div)},randomize);
}
);

}

ghost("#ghost");

});

</script>

Take note of where "function() {" is within .animate as it allows you to callback once the animation is completed.

Sunday, 21 October 2012

GridView Insert Select Delete Fields, Custom

I am still in the process of customising these fields, but to simply move this to the right for example, you can use:

<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" GridLines="None"
DataKeyNames="Category_ID" DataSourceID="CategoryDataSource"
CssClass="table" onrowcreated="GridView1_RowCreated"
PagerSettings-Mode="NextPreviousFirstLast" AutoGenerateDeleteButton="True">
<Columns>
<asp:BoundField DataField="Category_ID" HeaderText="Category ID"
SortExpression="Category_ID" Visible="false" />
<asp:BoundField DataField="Category_Title" HeaderText="Category Title"
SortExpression="Category_Title" />
<asp:CheckBoxField DataField="Category_Visible" HeaderText="Make Visible?"
SortExpression="Category_Visible" />
<asp:CommandField ShowEditButton="true" />
<asp:CommandField ShowDeleteButton="true" />
<asp:CommandField ShowInsertButton="true" />
</Columns>
</asp:GridView>

I will be updated this is due course with more information.


UPDATE:

Error: Delete is disabled for this control.

This was yet another simple but hard to find solution

On your Entitydatasource add EnableDelete="true" EnableInsert="true" EnableUpdate="true"

Now you can update your records as you wish.

Shame this wasnt more obivous as I wasted such a long time on this.






Friday, 19 October 2012

CookieParameters and Datasource's

Since the cookie support on DataSource controls for cookies is completely crap, my understanding is it is supposed to pull off the whole cookie(which is no use), if you need to pull of subkey values then doesnt work and it simply passes null.

To add this correctly, put the code in the page_load, this should hit the datasource before it has been rendered to the page.

This is the fastest in the way of 1 line.

Example:

NewsDataSource.WhereParameters.Add(new Parameter("RandomKey", DbType.String, Request.Cookies["CookieName"]["Key"]));

Note: When debugging things along these lines to see what value is passed to the database use sql profiler.