Archive

Archive for August, 2012

Client Side Validation with CustomValidator using JQuery

August 19, 2012 Leave a comment

Hi all,

try this example for Client Side Validation with CustomValidator using JQuery

1) Open VS2008 and create a new website and add new web page

2) From Toolbox drag Text-box and CustomValidator controls


Enter Code :
 <asp:TextBox ID="TextBoxCode" runat="server" Width="195px"></asp:TextBox>
 <asp:CustomValidator ID="CustomValidator6" runat="server" ControlToValidate="TextBoxCode"
 ErrorMessage="This code already exists Please enter another one."
 ForeColor="Red" ValidationGroup="InsertUpdate"
 ClientValidationFunction="CheckUniqueness"></asp:CustomValidator>
 <br />
 <asp:Button ID="Button1" runat="server" Text="Save" ValidationGroup="InsertUpdate"/>

3) In code behind add the following code


[WebMethod]
 [ScriptMethod]
 public static bool IsUnique(string code)
 {
 return false;
 }

4) Add this JavaScript to validate CustomValidator using Client Side


<script type="text/javascript">
 function CheckUniqueness(src, args) {
 var isValid;
 $.ajax({
 type: "POST",
 url: "Default.aspx/IsUnique",
 data: "{'code': '" + args + "'}",
 contentType: "application/json; charset=utf-8",
 dataType: "json",
 async: false,
 success: function(msg) {
 isValid = msg.d;
 }
 });
 args.IsValid = isValid;
 }
 </script>

after that run your page

Hope this helps

Good Luck.

Categories: ASP.Net, Javascript, Jquery

AJAX SlideShow Extender with Images from Folder

August 13, 2012 Leave a comment

Hi all,

try this example to use Ajax SlideShow Extender with Images from Folder

1) Open VS2008 and create a new website

2) Create Folder in website Root and add your images that you want to display using AJAX SlideShow Extender name it “Images”

3) Add WebSerive name it “Slideshow.asmx” and add the following Code


[System.Web.Services.WebMethod]
 [System.Web.Script.Services.ScriptMethod]
 public AjaxControlToolkit.Slide[] GetSlides()
 {
 string[] imagenames = System.IO.Directory.GetFiles(Server.MapPath("~/Images"));
 AjaxControlToolkit.Slide[] photos = new AjaxControlToolkit.Slide[imagenames.Length];
 for (int i = 0; i < imagenames.Length; i++)
 {
 string[] file = imagenames[i].Split('\\');
 photos[i] = new AjaxControlToolkit.Slide("Images/" + file[file.Length - 1], file[file.Length - 1], "");
 }
 return photos;
 }

4) Add new Web Page and ScriptManager , Image , Label , Three Buttons (For Play , Prev and Next) and AJAX SildeShow Extender


<ajax:ToolkitScriptManager ID="scriptmanager1" runat="server">
 </ajax:ToolkitScriptManager>
 <div>
 <table style="border: Solid 3px #D55500; width: 400px; height: 400px" cellpadding="0"
 cellspacing="0">
 <tr style="background-color: #D55500">
 <td style="height: 10%; color: White; font-weight: bold; font-size: larger" align="center">
 <asp:Label ID="lblTitle" runat="server"></asp:Label>
 </td>
 </tr>
 <tr>
 <td>
 <asp:Image ID="imgslides" runat="server" Height="400px" Width="400px" ImageUrl="~/Images/1.JPG" />
 </td>
 </tr>
 <tr>
 <td align="center">
 <asp:Label ID="lblimgdesc" runat="server"></asp:Label>
 </td>
 </tr>
 <tr>
 <td align="center">
 <asp:Button ID="btnPrevious" runat="server" Text="Prev" CssClass="button" />
 <asp:Button ID="btnPlay" runat="server" Text="Play" CssClass="button" />
 <asp:Button ID="btnNext" runat="server" Text="Next" CssClass="button" />
 </td>
 </tr>
 </table>
 <ajax:SlideShowExtender runat="server" AutoPlay="true" ImageTitleLabelID="lblTitle"
 ImageDescriptionLabelID="lblimgdesc" Loop="true" NextButtonID="btnNext" PreviousButtonID="btnPrevious"
 PlayButtonID="btnPlay" PlayButtonText="Play" StopButtonText="Stop" TargetControlID="imgslides"
 SlideShowServicePath="Slideshow.asmx" SlideShowServiceMethod="GetSlides">
 </ajax:SlideShowExtender>
 </div>

Hope this helps

Good Luck

Categories: AJAX, ASP.Net