Avoid “Show Unsecured Content” Message In HTTPS Sites

Standard

Hi All,

If you are developing a website which will be published in a secure socket layer (HTTPS) you may face some issues after publishing it for example a JavaScript may fall to run successfully and your web browser gives you a strange message tells you that this page contain unsecured content and give you the choice to view all content.

The problem here you added a reference to HTTP site in your page for example you use a JavaScript file which is hosted on an HTTP website

To avoid this problem you have to minimized depend on other websites as possible as you can

Find Control In ASP.NET Content Page

Standard

Hello everyone,

Have you ever tried to find an control using Page.FindControl() method in case that this page have a masterpage? if you answer is no, please try it and you will discover that this method won’t return any object, actually there is no direct way to make this.

Although the control is found in the page, ASP.NET consider that the control is located on the content placeholder control of the master page, so you have to get this control using the content place holder of the masterpage not the content control on the current page as following

Page.Master.FindControl(“ContentPlaceHolderID”).FindControl(“ControlName”);

Create RSS Feed With ASP.NET Framework 4.0

Standard

You can use the name space System.ServiceModel.Syndication in assembly System.ServiceModel which is added by default to new ASP.NET website project based on .net framework 4.0 ( I didn’t try it with .net framework 3.5 ).

Following is the code to view RSS to one channel called MyFeed and has items Hello1, Hello2 and Hello 3

1 – Create new aspx page

2 – Add the following code to its code behind in the page load handler

//Prepare the channel
Uri uri = new Uri(“http://helloworld”);
List<SyndicationItem> items = new List<SyndicationItem>();
for(int i = 0 ; i < 3 ; i ++)
{
         SyndicationItem item = new SyndicationItem();
         item.Title = new TextSyndicationContent(“hello”+ i);
         items.Add(item);
}
SyndicationFeed fe = new SyndicationFeed(“my feed”,”my description”,uri);
fe.Items = items;

//Add the RSS to the response
Response.Clear();
Response.ContentType = “application/rss+xml”;
Rss20FeedFormatter formater = new Rss20FeedFormatter(fe);

XmlWriter writer = XmlWriter.Create(Response.Output, null);
formater.WriteTo(writer);
writer.Flush();
Response.End();

3 – View it in you browser or try to add it to your outlook to see the charm of creating RSS with a little effort 🙂

Reference :http://deepumi.wordpress.com/2010/03/14/create-rss-2-0-and-atom-1-0-in-asp-net-3-5-csharp/

Validate a DropDown List Using Custom Validator

Standard

To do this Add a custom validator to your drop down like that


<asp:DropDownList ID="_districtDropDownList" runat="server" ></asp:DropDownList>
<asp:CustomValidator ID="_districtCustomValidator" runat="server"  
ErrorMessage="error message" ControlToValidate="_districtDropDownList"  
ClientValidationFunction="SelectTypeValidator">
</asp:CustomValidator> 
<script>

function SelectTypeValidator(sender, args)
{
   if (args.Value == "-1")  
         args.IsValid = false;   
  else args.IsValid = true;
} 
</script>

Custom validation method doesn’t fired if it used with textbox control and its value is empty

Standard

​To avoid using of the ValidatorEnable method to disable required field validator at some cases on textbox control I decided to use custom validator as a required field just like the following:

<asp:CustomValidator ID="_examDateCustomValidator" runat="server" Text="*"
 ClientValidationFunction="CustomValidateDDL" ControlToValidate="_textbox">

And here is the javascript validation method

function CustomValidateDDL(sender, args)
{
  if (args.Value == "")
      args.IsValid = false;
  else
       args.IsValid = true;
}

unfortunatily I found that this method is working well if I compare the value with any other value except empty text

Execute $(Document).Ready After UpdatePanel PostBack

Standard

Add the following code following code to your page and replace the commented line with your code

Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
function EndRequestHandler(sender, args)
{
  if (args.get_error() == undefined)
  {
    //Add the method which must run after postback here
  }
}