Enabling AJAX in SharePoint applications was a really tough job, I spent a lot of time to get it work and now I want to save time of others developers. Just follow me on the steps and at the end we will be able to add a web part with AJAX functionality.

I am dividing my post in 2 steps

STEP 1 : in step 1 I will do the necessary web.config modifications. I am pulling all these settings through “FeatureInstalled” event of a feature with Web Application level scope, have a look at the following code

<?xml version=”1.0″ encoding=”utf-8″ ?>

<Feature Id=”c9cf98e2-cc0e-4464-914c-4c974ec2e133″

Scope=”Web”

Title=”UI Feature ”

Description=”This feature enables the UI functionality within a SharePoint Site.”

Version=”1.0.0.0″

Creator=”Shafaqat Ali”

SolutionId=”62298653-d7de-4b56-b50f-5df3d116e590″

ImageUrl=””

ImageUrlAltText=”My Feature Icon”

Hidden=”FALSE”

ActivateOnDefault=”FALSE”

AlwaysForceInstall=”FALSE”

AutoActivateInCentralAdmin=”FALSE”

RequireResources=”FALSE”

DefaultResourceFile=”MyResourceFile”

ReceiverAssembly=”UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6669f18c4e55eb20″

ReceiverClass=”UI.UIFeatureReceiver”

xmlns=”http://schemas.microsoft.com/sharepoint/”&gt;

<ElementManifests>

<ElementManifest Location=”Elements.xml” />

</ElementManifests>

</Feature>

Feature receiver code behind file, lengthy code you can copy paste it.

/***********************************************************************************

public override void FeatureInstalled(SPFeatureReceiverProperties properties) {

#region Extend the SharePoint web.config file, which is typically found in a directory with the following structure

//For ASP.NET 2.0 AJAX Extensions

//1. Add the following <sectionGroup> elements within the <configSections> element.

SPWebConfigModification sectionGroup = this.GetConfigurationSettingsforAJAX();

//2. Add the following controls declaration within the <pages> element, which is located within the <system.web> element.

SPWebConfigModification controlInPages = this.GetControlInPagesSettings();

//3. Add the following assembly declaration within the <assemblies> element.

SPWebConfigModification assembly1 = this.GetAssembly1Settings();

//4. Add the following verb handlers within the <httpHandlers> element.

SPWebConfigModification verb1 = this.GetVerb1Settings();

SPWebConfigModification verb2 = this.GetVerb2Settings();

SPWebConfigModification verb3 = this.GetVerb3Settings();

SPWebConfigModification verb4 = this.GetVerb4Settings();

//5. Add the following script module handler within the <httpModules> element.

SPWebConfigModification scriptmodulehandler = this.GetScriptModuleSettings();

//6.  Add the following safe control entry within the <SafeControls> element, which is located within the <SharePoint> element.

SPWebConfigModification safecontrol = this.GetSafeControlsSettings();

//7. Add the following scripting web service handlers within the <configuration> element.

SPWebConfigModification systemwebextensions = this.GetWebExtensionsSettings();

// These settings are required for AJAX implemenation

SPWebConfigModification systemwebServer = this.GetSystemWebServerSettings();

#endregion

//System.Diagnostics.Debug.Assert(false);

// Iterate through all the Web Applications and apply the changes

SPWebApplicationCollection webAppCollection = SPWebService.ContentService.WebApplications;

System.Collections.IEnumerator enumerator = webAppCollection.GetEnumerator();

while (enumerator.MoveNext())

{

SPWebApplication webApplication = (SPWebApplication)enumerator.Current;

//SPWeb web = properties.Feature.Parent;

webApplication.WebConfigModifications.Add(sectionGroup); webApplication.WebConfigModifications.Add(controlInPages);

webApplication.WebConfigModifications.Add(assembly1);

webApplication.WebConfigModifications.Add(verb2);

webApplication.WebConfigModifications.Add(verb3);

webApplication.WebConfigModifications.Add(verb4);

webApplication.WebConfigModifications.Add(scriptmodulehandler);

webApplication.WebConfigModifications.Add(safecontrol);

webApplication.WebConfigModifications.Add(systemwebextensions);

webApplication.WebConfigModifications.Add(systemwebServer);

webApplication.Update(true);

webApplication.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications();

}

// We also want to propagate these web.config changes across the farm

//SPFarm.Local.Services.GetValue<SPWebService>().ApplyWebConfigModifications();

}

private SPWebConfigModification GetConfigurationSettingsforAJAX()

{

SPWebConfigModification sectionGroup = new SPWebConfigModification();

sectionGroup.Path = “configuration/configSections”;

sectionGroup.Name = “sectionGroup[@name=’system.web.extensions’][@type=’System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35′]”;

sectionGroup.Sequence = 4;

sectionGroup.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;

sectionGroup.Value = “<sectionGroup name=’system.web.extensions’ type=’System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35′>”

+ “<sectionGroup name=’scripting’ type=’System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35′>”

+ “<section name=’scriptResourceHandler’ type=’System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35′ requirePermission=’false’ allowDefinition=’MachineToApplication’ />”

+ “<sectionGroup name=’webServices’ type=’System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35′>”

+ “<section name=’profileService’ type=’System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35′ requirePermission=’false’ allowDefinition=’MachineToApplication’ />”

+ “<section name=’authenticationService’ type=’System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35′ requirePermission=’false’ allowDefinition=’MachineToApplication’ />”

+ “</sectionGroup></sectionGroup></sectionGroup>”;

return sectionGroup;

}

private SPWebConfigModification GetControlInPagesSettings()

{

SPWebConfigModification controlInPages = new SPWebConfigModification();

controlInPages.Path = “configuration/system.web/pages”;

controlInPages.Name = “controls”;

controlInPages.Sequence = 6;

controlInPages.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;

controlInPages.Value = “<controls><add tagPrefix=’asp’ namespace=’System.Web.UI’ assembly=’System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35′ /></controls>”;

return controlInPages;

}

private SPWebConfigModification GetAssembly1Settings()

{

SPWebConfigModification assembly1 = new SPWebConfigModification();

assembly1.Path = “configuration/system.web/compilation/assemblies”;

assembly1.Name = “add[@assembly=’System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35′]”;

assembly1.Sequence = 7;

assembly1.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;

assembly1.Value = “<add assembly=’System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35′ />”;

return assembly1;

}

private SPWebConfigModification GetVerb1Settings()

{

SPWebConfigModification verb1 = new SPWebConfigModification();

verb1.Path = “configuration/system.web/httpHandlers”;

verb1.Name = “remove[@verb=’*’][@path=’*.asmx’]”;

verb1.Sequence = 8;

verb1.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;

verb1.Value = “<!–<remove verb=’*’ path=’*.asmx’ />–>”;

return verb1;

}

private SPWebConfigModification GetVerb2Settings()

{

SPWebConfigModification verb2 = new SPWebConfigModification();

verb2.Path = “configuration/system.web/httpHandlers”;

verb2.Name = “add[@verb=’*’][@path=’*.asmx’][@validate=’false’][@type=’System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35′]”;

verb2.Sequence = 9;

verb2.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;

verb2.Value = “<add verb=’*’ path=’*.asmx’ validate=’false’ type=’System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35′ />”;

return verb2;

}

private SPWebConfigModification GetVerb3Settings()

{

SPWebConfigModification verb3 = new SPWebConfigModification();

verb3.Path = “configuration/system.web/httpHandlers”;

verb3.Name = “add[@verb=’*’][@path=’*_AppService.axd’][@validate=’false’][@type=’System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35′]”;

verb3.Sequence = 10;

verb3.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;

verb3.Value = “<add verb=’*’ path=’*_AppService.axd’ validate=’false’ type=’System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35′ />”;

return verb3;

}

private SPWebConfigModification GetVerb4Settings()

{

SPWebConfigModification verb4 = new SPWebConfigModification();

verb4.Path = “configuration/system.web/httpHandlers”;

verb4.Name = “add[@verb=’GET,HEAD’][@path=’ScriptResource.axd’][@type=’System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35′][@validate=’false’]”;

verb4.Sequence = 11;

verb4.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;

verb4.Value = “<add verb=’GET,HEAD’ path=’ScriptResource.axd’ type=’System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35′ validate=’false’ />”;

return verb4;

}

private SPWebConfigModification GetScriptModuleSettings()

{

SPWebConfigModification scriptmodulehandler = new SPWebConfigModification();

scriptmodulehandler.Path = “configuration/system.web/httpModules”;

scriptmodulehandler.Name = “add[@name=’ScriptModule’][@type=’System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35′]”;

scriptmodulehandler.Sequence = 12;

scriptmodulehandler.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;

scriptmodulehandler.Value = “<add name=’ScriptModule’ type=’System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35′ />”;

return scriptmodulehandler;

}

private SPWebConfigModification GetSafeControlsSettings()

{

SPWebConfigModification safecontrol = new SPWebConfigModification();

safecontrol.Path = “configuration/SharePoint/SafeControls”;

safecontrol.Name = “SafeControl[@Assembly=’System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35′][@Namespace=’System.Web.UI’][@TypeName=’*’][@Safe=’True’]”;

safecontrol.Sequence = 13;

safecontrol.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;

safecontrol.Value = “<SafeControl Assembly=’System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35′ Namespace=’System.Web.UI’ TypeName=’*’ Safe=’True’ />”;

return safecontrol;

}

private SPWebConfigModification GetWebExtensionsSettings()

{

SPWebConfigModification systemwebextensions = new SPWebConfigModification();

systemwebextensions.Path = “configuration”;

systemwebextensions.Name = “system.web.extensions”;

systemwebextensions.Sequence = 14;

systemwebextensions.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;

systemwebextensions.Value = “<system.web.extensions><scripting><webServices></webServices></scripting></system.web.extensions>”;

return systemwebextensions;

}

private SPWebConfigModification GetSystemWebServerSettings()

{

SPWebConfigModification systemwebServer = new SPWebConfigModification();

systemwebServer.Path = “configuration”;

systemwebServer.Name = “system.webServer”;

systemwebServer.Sequence = 15;

systemwebServer.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;

systemwebServer.Value = “<system.webServer><validation validateIntegratedModeConfiguration=’false’ /><modules><add name=’ScriptModule’ preCondition=’integratedMode’ type=’System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35′ />”

+ “</modules><handlers><remove name=’WebServiceHandlerFactory-Integrated’ /><add name=’ScriptHandlerFactory’ verb=’*’ path=’*.asmx’ preCondition=’integratedMode’ type=’System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35′ />”

+ “<add name=’ScriptHandlerFactoryAppServices’ verb=’*’ path=’*_AppService.axd’ preCondition=’integratedMode’ type=’System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35′ />”

+ “<add name=’ScriptResource’ preCondition=’integratedMode’ verb=’GET,HEAD’ path=’ScriptResource.axd’ type=’System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35′ /></handlers></system.webServer>”;

return systemwebServer;

}

***********************************************************************************/

Step 1 is complete, all required settings for AJAX functionality have been implemented, you can check AJAX functionality by adding a simple logic on any page your sharepoint site.

Let’s move to step 2

STEP2

create a simple class say “MyFirstWebPart” and inherit it form “Microsoft.SharePoint.WebPartPages.WebPart” class

public class MyFirstWebPart: Microsoft.SharePoint.WebPartPages.WebPart

{

private string imagepath;

[DefaultValue(“”), WebBrowsable(true), Category(“ProgressTemplate”), Personalizable(PersonalizationScope.Shared)]

public string ImagePath

{

get { return imagepath; }

set { imagepath = value; }

}

private string disptext;

[DefaultValue(“”), WebBrowsable(true), Category(“ProgressTemplate”), Personalizable(PersonalizationScope.Shared)]

public string DisplayText

{

get { return disptext; }

set { disptext = value; }

}

protected override void CreateChildControls()

{

base.CreateChildControls();

UpdatePanel updatePanel1 = new UpdatePanel();

updatePanel1.ID = “udpItemListingWebPart”;

updatePanel1.UpdateMode = UpdatePanelUpdateMode.Conditional;

UpdateProgress updateProgress1 = new UpdateProgress();

updateProgress1.AssociatedUpdatePanelID = “udpItemListingWebPart”;

updateProgress1.ProgressTemplate = new ProgressTemplate(ImagePath, DisplayText);

Button button1 = new Button();

button1.ID = “btnClick”;

button1.Text = “Update”;

button1.Click += new EventHandler(button1_Click);

Label label1 = new Label();

label1.ID = “lblShowTime”;

label1.Text = string.Format(“Updated at: {0} “, DateTime.Now.ToLongTimeString());

updatePanel1.ContentTemplateContainer.Controls.Add(label1);

updatePanel1.ContentTemplateContainer.Controls.Add(button1);

this.Controls.Add(updateProgress1);

ScriptManager sc = new ScriptManager();

this.Controls.AddAt(0, sc);

this.Controls.Add(updatePanel1);

}

void button1_Click(object sender, EventArgs e)

{

//this.label1.Text = string.Format(“Updated at: {0} “, DateTime.Now.ToLongTimeString());

}

protected override void Render(HtmlTextWriter writer)

{

base.Render(writer);

if (!this.Page.IsAsync)

{

string script = “”;

script = @”

var ITEMLISTINGBUTTONID;

with(Sys.WebForms.PageRequestManager.getInstance()){

add_beginRequest(onBeginRequest);

add_endRequest(onEndRequest);

}

function onBeginRequest(sender, args){

ITEMLISTINGBUTTONID = args.get_postBackElement().id;

$get(ITEMLISTINGBUTTONID).parentElement.style.display = ‘none’;

}

function onEndRequest(sender, args){

$get(ITEMLISTINGBUTTONID).parentElement.style.display = ”;

}

“;

this.Page.ClientScript.RegisterStartupScript(this.GetType(), “HideSimpleAJAXWebPartUDP”, script, true);

}

}

}

public class ProgressTemplate : ITemplate

{

private string imagepath;

public string ImagePath

{

get { return imagepath; }

set { imagepath = value; }

}

private string disptext;

public string DisplayText

{

get { return disptext; }

set { disptext = value; }

}

public ProgressTemplate(string imagePath, string displayText)

{

ImagePath = imagePath;

DisplayText = displayText;

}

public void InstantiateIn(Control container)

{

Image img = new Image();

img.ImageUrl = SPContext.Current.Site.Url + “/” + ImagePath;

Label lbl = new Label();

lbl.Text = DisplayText;

container.Controls.Add(img);

container.Controls.Add(lbl);

}

}

Now add your assembly to safe controls list

<SafeControl Assembly=”YourAssemblyName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6669f18c4e55eb20″ Namespace=”UI.Code” TypeName=”*” Safe=”True” />

Refresh the page you will see this screen

1

I know the code is very complex, try at your end, if you find any problem or stuck anywhere do contact me.

ASP.NET 4.0 has many improvements for different set of scenarios such as Webforms, Dynamic Data & AJAX based web development.  There are also a lot of enhancements to the core runtime that powers ASP.NET such as Caching, Session & Request/Response objects.

For this post, we will examine some of the web form enhancements.  There are sure a lot of them and we will examine some of them in the future posts.

Controlling View State using the ViewStateMode Property – Performance Enhancement

One of the most complained thing in ASP.NET Webform is the growing viewstate which becomes a concern for performance.  While earlier you can set the EnableViewState property to true or false, post that, all the controls, by default inherit and even if you set it to enabled at control level, the behaviour was inconsistent.

With ASP.NET 4.0, the ViewStateMode property helps to determine for every control, whether the ViewState should be enabled, disabled or inherited accordingly.  Ex.-

<asp:Panel ID=”pnlViewState” runat=”server” ViewStateMode=”Disabled”>
Disabled: <asp:Label runat=”server”  Text=”Value set in markup” ViewStateMode=”Inherit” /><br />
Enabled: <asp:Label  runat=”server” Text=”Value set in markup” ViewStateMode=”Enabled” />
<hr />
<asp:button ID=”Button1″ runat=”server”  Text=”Postback” />
</asp:Panel>

In the code-behind

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
label1.Text = “Value set in code behind”;
label2.Text = “Value set in code behind”;
}
}

When you run the above page, you can find that the intial value for both the labels is set to “Value set in code behind” whereas after clicking on the button (postback), the value of label1 changes to “Value set in markup” whereas the value of label2 remains unchanged.  As you can see, the Panel which holds both these lables has ViewStateMode set to Disabled and label1 is inherting the mode (this is the default if not specified) and label2 has it enabled.  That is the reason label2 maintains viewstate while label1 loses it.

While it is arguably possible using the simple EnableViewState property earlier, it was never consistent.  Considering the fact that in most of our performance sessions, we talk about disabling viewstate and then enabling it at control level while it doesnt work, this ViewStateMode is a welcome architectural change to improve performance.

Debugging the SharePoint Timer job was really a tough job for me, i searched on the web and found so many solutions but they did not work at my system (i dont know why). Finally i did a trick to debugg the timer service, i added the following line of code in the timer service job where you want to have a break point:

1

after compiling the solution and restarting my timer service it came with the following popup options :

2

  • Abort– means you want to stop timer service instance
  • Retry- means you want to debugg the code
  • ignore- means ignore this message and continue the execution of the code

for debugging i selected retry and it opened another screen

3

selected new instance of CLR debugger, it showed the following screen

4

after pressing F10 two times it did enable debugging like this

5

here i did normal debugging by pressing F10 and F11 keys

6

you can also use breakpoints here

7

hope this helps

if you think this is helpfull , dont forget to leave a comment.

We usually use Singleton design pattern where only one object of a class is required. It is very simple and I try to explain it.

public class MyClass

{

static MyClass myclass;

// make constructor private

// now you cannot make a direct instance of this class like:

// MyClass obj=new MyClass() // it wount compile

private MyClass()

{

}

public static MyClass GetInstance()

{

lock (typeof(MyClass))

{

if (myclass == null)

{

myclass = new MyClass();

}

}

return myclass;

}

//Destructor

~MyClass()

{

myclass = null;

}

}

Concept behind this patteren is very simple, we create a static object of a class which remains in memory until destroyed by the destructor.when we try to make another object of this class our method will check the existing instance, if already exist then retun the existing object otherwise create a new object.

Now call the static method using this line of codes

MyClass obj=MyClass.GetInstance();

if it is helpful, plese dont forget to leave a comment.

Abstract:
ASP.NET includes the TextBox control and the Validation controls which can be combined together to perform user input validation. The caveat is that the developer has to use two different controls to perform a simple validation. In this article we are going to create a custom TextBox control which will use different validation controls and reduce the complexity of using multiple controls.

Getting Started:

We have created a separate class library project called MyControlsLibrary which will host all the server controls. We will call our control RequiredTextBox control. The RequiredTextBox control will derive from the ASP.NET TextBox control and add the validators as composite controls. Let’s add a RequiredFieldValidator to the RequiredTextBox control.

Adding a RequiredFieldValidator to the RequiredTextBox Control:

Our first task is to add a RequiredFieldValidator to our new RequiredTextBox control. Here is the code:

public class RequiredTextBox : TextBox
{
public string RequiredTextBoxErrorMessage { get; set; }

private RequiredFieldValidator _requiredFieldValidator;

protected override void CreateChildControls()

{
CreateRequiredFieldValidator();

base.CreateChildControls();
}
private void CreateRequiredFieldValidator()
{
_requiredFieldValidator = new RequiredFieldValidator
{
ControlToValidate = ID,
ErrorMessage = RequiredTextBoxErrorMessage
};

Controls.Add(_requiredFieldValidator);
}

protected override void Render(HtmlTextWriter writer)
{
base.Render(writer);
_requiredFieldValidator.RenderControl(writer);

}
}

The first thing to notice is the name of the property “RequiredTextBoxErrorMessage”. We have provided a descriptive property name instead of the simple “ErrorMessage”. The reason is that we will be adding other validators which will also have the ErrorMessage property. So, we are differentiating the validator error message properties by using descriptive names.

The CreateRequiredFieldValidator method is fired on the PreRender event and is used to create the RequiredFieldValidator control and then add it to the controls collection.

Using the RequiredTextBox Control:

Let’s use our new RequiredTextBox control on a ASP.NET page. The first thing that you must do is add a reference to the MyControlsLibrary class library project. Now, you need to register the assembly to the page so you can use the new RequiredTextBox control.

<%@ Register Assembly=”MyControlsLibrary” Namespace=”MyControlsLibrary” TagPrefix=”mycontrols” %>

And here is the usage of the control:

<form id=”form1″ runat=”server”>
<div>

<mycontrols:RequiredTextBox ID=”txtName” runat=”server” RequiredTextBoxErrorMessage=”This field cannot be left empty!” />

</div>
</form>

if it is helpful, plese dont forget to leave a comment.

letter-of-resignation-mabdullah

if (FileUpload1.PostedFile != null)
{
string ImageName = “SampleImage.jpg”;
//FileUpload1.SaveAs(Server.MapPath(“Images\\”) + ImageName);

System.Drawing.Image MainImage = System.Drawing.Image.FromStream(FileUpload1.PostedFile.InputStream);
System.Drawing.Image.GetThumbnailImageAbort myCallback =
new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);
System.Drawing.Image Thumbnailimage = MainImage.GetThumbnailImage(600, 600, myCallback, IntPtr.Zero);

string ThumbnailPath = Server.MapPath(“ThumbnailImages\\”) + ImageName;
Thumbnailimage.Save(ThumbnailPath);

using (System.Drawing.Image TargetImage = Thumbnailimage)
{
using (System.Drawing.Image Thumbnail =
TargetImage.GetThumbnailImage(100, 100, myCallback, IntPtr.Zero))
{
Thumbnail.Save(Server.MapPath(“Images\\abc.jpg”));
Thumbnail.Dispose();
}
TargetImage.Dispose();
}
Thumbnailimage.Dispose();

}

if it is helpful, plese dont forget to leave a comment.