Disable Submit button after submit information

Posted by Venkat | Labels: ,

Here we have to discuss the ie: how to disable the submit button after you submit the details for example: user are sending some value to database or storing user information so after storing the information i have to disable the submit button to avoid duplicate insertion ie: insert two or more times.


protected void Page_Load(object sender, EventArgs e)
{
string clickHandler = string.Format(
"document.body.style.cursor = 'wait'; this.value='Please wait...'; this.disabled = true; {0};",
this.ClientScript.GetPostBackEventReference(Button1, string.Empty));
Button1.Attributes.Add("onclick", clickHandler);
}

protected void Button1_Click(object sender, EventArgs e)
{
// Emulate a lengthy process of 10 seconds...
TimeSpan waitTime = new TimeSpan(0, 0, 0, 10);
System.Threading.Thread.Sleep(waitTime);

Response.Write("Button1_Click fired
");
}

Validate Decimal numbers

Posted by Venkat | Labels: ,

Now we are going to discuss about the validate the decimal numbers it should be in the format of


<asp:TextBox ID="Phone_TextBox" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="RegularExpressionValidator"
ValidationExpression="^\d+\.\d{2}$" ValidationGroup="phone" ControlToValidate="Phone_TextBox">it should be 125.00 this format</asp:RegularExpressionValidator>
<asp:Button ID="Button1" runat="server" Text="Button" ValidationGroup="phone" /></div>


Matches

142.00
254.25 etc

Non-Matches

214
25.0
254.5
254.355

code:

PreviousPage Type

Posted by Venkat | Labels: ,

Hi , we already seen the CrossPage Posting so now we are going to see the concept Previouspage ( to send data from one page to another page )

in the first page ie: Webform1.aspx


<asp:TextBox ID="TextBox1" Text="xxxx" runat="server" />
<asp:LinkButton ID="LinkButton1" runat="server" Text="L”schen" PostBackUrl="~/webform2.aspx" />

On Webform2.aspx you have to write it on page Directive, you have to specify the page so from that page you can get the textbox value to this page. In the Virtualpath you should specify the Previous page name from where you get the control value.

<%@ PreviousPageType VirtualPath="~/Webform1.aspx" %>

on Codebehind ie: Page_load event write this

if (Page.PreviousPage != null)
{
TextBox oTextBox = (TextBox)Page.PreviousPage.FindControl("TextBox1");
if (oTextBox != null)
{
Response.Write(oTextBox.Text);
}
}

Sys is Undefined

Posted by Venkat | Labels: ,

When i add ajaxtoolkit.dll file to bin folder of my new project that has been created in .net 2005 or .net 2.0 so when i place the ajax controls on my page and written some code on running the project it shows no error but code is not working on status bar i have see Error on this page

When i click the error icon it shows Sys is undefined

so the solution is you have to modify the web.config file like this.

1) Below <Configuraion> tag add this


<configSections>
<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="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="Everywhere"/>
<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>
</configSections>


2) Below <system.web> add the settings

<pages>
<controls>
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</controls>
</pages>


3) Then find compilation debug="false" change like this


<compilation debug="true">
<assemblies>
<add assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</assemblies>
</compilation>

4) Then below the compilation settings

<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<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"/>
<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"/>
</httpHandlers>
<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</httpModules>


5) Then after </system.web> add the settings

<system.web.extensions>
<scripting>
<webServices>
<!-- Uncomment this line to customize maxJsonLength and add a custom converter -->
<!--
<jsonSerialization maxJsonLength="500">
<converters>
<add name="ConvertMe" type="Acme.SubAcme.ConvertMeTypeConverter"/>
</converters>
</jsonSerialization>
-->
<!-- Uncomment this line to enable the authentication service. Include requireSSL="true" if appropriate. -->
<!--
<authenticationService enabled="true" requireSSL = "true|false"/>
-->
<!-- Uncomment these lines to enable the profile service. To allow profile properties to be retrieved
and modified in ASP.NET AJAX applications, you need to add each property name to the readAccessProperties and
writeAccessProperties attributes. -->
<!--
<profileService enabled="true"
readAccessProperties="propertyname1,propertyname2"
writeAccessProperties="propertyname1,propertyname2" />
-->
</webServices>
<!--
<scriptResourceHandler enableCompression="true" enableCaching="true" />
-->
</scripting>
</system.web.extensions>

6) Then add the system.webserver settings

<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>


These are the setting you have to modify on your web.config if your are selecting the AJAX - Enabled Websites when you are creating the project so at that time there is no need these setting, these settings are added automatically.

All the best

Cross Page Posting

Posted by Venkat | Labels:

Cross page posting is submitting the form to a different page. This is usually required when you are creating a multi page form to collect information from the user on each page. When moving from the source to the target page, the values of controls in the source page can be accessed in the target page.

To use cross-page posting, you have to use the PostBackURL attribute to specify the page you want to post to.

First we place the two page Default.aspx and Default2.aspx , so now we are going to pass the Controls value from default page to default2 page.

in Default.aspx page place one button and Textbox Control as shown below


<:TextBox ID="TextBox1" runat="server" Text="Welcome to .NET"></asp:TextBox>

<asp:Button ID="Button1" runat="server" PostBackUrl="~/Default.aspx" Text="TargetButton" />

And in the Default2.aspx page write the below code on page load and also make sure you have to place the label control on this page


<asp:Label ID="Label1" runat="server" ></asp:Label>

if (Page.PreviousPage != null)
{
TextBox btn = (TextBox)(Page.PreviousPage.FindControl("TextBox1"));
Label1.Text = btn.Text;
}

Add Default value to Databound Dropdownlist

Posted by Venkat | Labels:

Now we are going to see how to add Default value to Databound Dropdownlistcontrol

First Case : When user binding the dropdownlist using SqlDataSource so you have to keep in mind to use AppendDatabounditemd="True". then only you can able to add the item manually to Databound Dropdownlist Control



<asp:DropDownList ID="DropDownListFinFile" runat="server" DataSourceID="ObjectDataSourceFinFile" AutoPostBack="True" DataTextField="FinFileName" DataValueField="FinFileId" CssClass="tabletext" AppendDataBoundItems="true">
<asp:ListItem Text="Please select" Value="">-1</asp:ListItem>

<asp:DropDownList>


Send Email using Vb.NET

Posted by Venkat | Labels: , ,

Now we have to discuss how to send email using GMAIL server.

Normally we can use , Gmail, Yahoo , etc.. some company having own mailserver so you have to contact your Admin to know your mailserver , id , pwd etc..

This is code to send email using Vb.Net

Imports System.Net.Mail

Protected  Sub Button1_Click
(ByVal sender As Object, ByVal e As EventArgs)
Dim mail As MailMessage =  New MailMessage()
mail.To.Add("admin@gmail.com")
mail.From = New MailAddress("admin@gmail.com")
mail.Subject = "Email using Gmail server "

dim Body as String = "Hi, this mail is to test sending mail"+
             "using Gmail in ASP.NET using vb.Net"
mail.Body = Body

mail.IsBodyHtml = True
Dim smtp As SmtpClient =  New SmtpClient()
smtp.Host = "smtp.gmail.com" 
smtp.EnableSsl = True 
smtp.Credentials = New System.Net.NetworkCredential
    ("YourUserName@gmail.com","YourGmailPassword")
smtp.Send(mail)
End Sub

Send Email using CSharp.Net

Posted by Venkat | Labels: ,

Now we have to discuss how to send email using GMAIL server.

Normally we can use , Gmail, Yahoo , etc.. some company having own mailserver so you have to contact your Admin to know your mailserver , id , pwd etc..

This is code to send email using Asp.net user port no is 587 or 465 it depends upon system

declare the port below the smtp server name

smtp.port=587

using System.Net.Mail;


//Now write this code in click event of button

//C# code

protected void Button1_Click(object sender, EventArgs e)
{
  MailMessage mail = new MailMessage();
  mail.To.Add("admin@gmail.com");
  mail.From = new MailAddress("admin@gmail.com");
  mail.Subject = "Email using Gmail";

  string Body = "Hi, this mail is to test sending mail"+
                "using Gmail in ASP.NET using C#";
  mail.Body = Body;

  mail.IsBodyHtml = true;
  SmtpClient smtp = new SmtpClient();
  smtp.Host = "smtp.gmail.com"; 
  smtp.EnableSsl = true; 
  smtp.Credentials = new System.Net.NetworkCredential
       ("YourUserName@gmail.com","YourGmailPassword");
    smtp.Send(mail);
}

//you have to give your Gmail Username and password ..

Validate UniqueIdentifier

Posted by Venkat | Labels: ,

Here we have to discuss about how to validation UniqueIdentifiere using REGEX


Here is the Expression


^\w{7}-\w{4}-\w{4}-\w{4}-\w{12}

How to place favicon in the address bar

Posted by Venkat | Labels:

Here we have to discuss about how to place the favicon on the address bar or ASP.NET Websites

You have to put this code on your head Section of your Html page..

<link rel="shortcut icon" type="image/ico" href="~/favicon.ico">


and here is web site that will convert any pic to icon

http://www.html-kit.com/favicon/



Embedding the image with an Email

Posted by Venkat | Labels: , ,

We have to discuss about how to Embed an image to Email Previous Article we are discussed passing image URL directly to body tag of Email.

So , now we Embed a Image directly to Email

See the example...

try

{

MailMessage mail = new MailMessage();

mail.To.Add("user@gmail.com");

mail.From = new MailAddress("admin@support.com");

mail.Subject = "Test with Image";

string Body = "<b> Welcome to Embed image!</b><br><BR>Online resource for .net articles.<BR><img alt=\"\" hspace=0 src=\"cid:imageId\" align=baseline border=0 >";


AlternateView htmlView = AlternateView.CreateAlternateViewFromString(Body, null, "text/html");

LinkedResource imagelink = new LinkedResource(Server.MapPath(".") + @"\images\sample.jpg", "image/jpg");


imagelink.ContentId = "imageId";

imagelink.TransferEncoding = System.Net.Mime.TransferEncoding.Base64;

htmlView.LinkedResources.Add(imagelink);

mail.AlternateViews.Add(htmlView);

SmtpClient smtp = new SmtpClient();

smtp.Host = "smtp.gmail.com";

//specify your smtp server name/ip here
smtp.EnableSsl = true;

//enable this if your smtp server needs SSL to communicate
smtp.Credentials = new NetworkCredential("username", "password");

// smtp.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;

smtp.Send(mail);

}

catch (Exception ex)

{

Response.Write(ex.Message);

}

Embedding the image using image URL

Posted by Venkat | Labels: ,

Hi Good day to all

Here We have to discuss about , how to embed the image to an email actually , Embedding an image will affect performance so here , i am passing the image URL directly to the body tag

so , here the code..


try

{

MailMessage mail = new MailMessage();

mail.To.Add("user@gmail.com");

mail.From = new MailAddress("admin@support.com");

mail.Subject = "Test with Image";

string Body = "<b>Welcome to Pass Image URL to Email Body!</b><br><BR>Online resource for .net articles.<BR><img alt=\"\" hspace=0 src='http://www.idealsd.co.uk/images/addmenu.jpg' align=baseline border=0 >";


AlternateView htmlView = AlternateView.CreateAlternateViewFromString(Body, null, "text/html");

mail.AlternateViews.Add(htmlView);

SmtpClient smtp = new SmtpClient();

smtp.Host = "smtp.gmail.com";

//specify your smtp server name/ip here
smtp.EnableSsl = true;

//enable this if your smtp server needs SSL to communicate
smtp.Credentials = new NetworkCredential("Username", "password");

// smtp.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;

smtp.Send(mail);

}

catch (Exception ex)

{

Response.Write(ex.Message);

}

ASP Snippets | Issue - allowDefinition = 'MachineToApplication' beyond application level

Posted by Venkat |

Validate the numbers

Posted by Venkat | Labels: ,

It wont allow spaces before or after the digits but it wont if there are only spaces so you need RequiredFieldValidator too
the RegularExpressionValidator to validate the phone number without using JavaScript. So something like this:

<asp:regularexpressionvalidator id="RegularExpressionValidator1">
ControlToValidate="TextBox1"
ValidationExpression="\d+"
Display="Static"
EnableClientScript="true"
ErrorMessage="Please enter numbers only"
runat="server"/>

StringBuilder sample Example -1

Posted by Venkat | Labels: ,

Here we have to see the sample of stringbuilder ,

System.StringBuilder is mutable where variety of operations can be performed

System.String is immutable variable value may change BUT original data value will be discarded and new value will be in memory.

Add one listbox on your webform and add three items on design mode.

protected void Page_Load(object sender, EventArgs e)
{
StringBuilder builder = new StringBuilder();
for (int i = 0; i < array =" new" x =" this.ListBox1.Items[i].ToString();"> 0)
{
if ((builder.Length) != (ListBox1.Items.Count))
{

builder.Append(",");
// x += ",";
}
}

// Response.Write(builder);

}
string s = builder.ToString();
s = s.Substring(0, s.Length - 1);
Response.Write(s);
}

Get absolute path on tinymce Editor Control

Posted by Venkat | Labels:

Here we are going to discuss how to get the absolute path of the image or link on tinyMCE Editor contorl , by default it took relative path of the image so here it line you have to include on your script of your page.

relative_urls: false,

PayOffers.in