tag:blogger.com,1999:blog-24661518655996822872024-03-13T12:55:34.427-07:00Asp Net, C#.Net and VB.Net Code Examples, Sql Server Examples and Tutorials for All Technologies.Net Code Examples, SQL Server Examples and Tutorials For All Technologies.
Find what you want?Anonymoushttp://www.blogger.com/profile/12091988898339694270noreply@blogger.comBlogger58125tag:blogger.com,1999:blog-2466151865599682287.post-23302819825104409442016-10-12T01:16:00.003-07:002016-10-12T01:16:49.775-07:00Serialize dataset to xml in webservice .net<div dir="ltr" style="text-align: left;" trbidi="on">
<b>Create a class for extension:</b><br />
<br />
public static class Extensions<br />
{<br />
public static string ToXml(this DataSet ds)<br />
{<br />
using (var mStream = new MemoryStream())<br />
{<br />
using (TextWriter sWriter = new StreamWriter(mStream))<br />
{<br />
var xmlSerializer = new XmlSerializer(typeof(DataSet));<br />
xmlSerializer.Serialize(sWriter, ds);<br />
return Encoding.UTF8.GetString(mStream.ToArray());<br />
}<br />
}<br />
}<br />
}</div>
Anonymoushttp://www.blogger.com/profile/12091988898339694270noreply@blogger.com0tag:blogger.com,1999:blog-2466151865599682287.post-70140970333043726022016-07-27T09:59:00.000-07:002016-07-27T09:59:09.114-07:00How to call web api using Ajax call<div dir="ltr" style="text-align: left;" trbidi="on">
<script><br />
$(document).ready(function () {<br />
$("#Save").click(function () {<br />
<br />
var person = new Object();<br />
person.name = $('#name').val();<br />
person.surname = $('#surname').val();<br />
<br />
$.ajax({<br />
url: 'http://localhost:11023/api/values/Get',<br />
type: 'POST',<br />
dataType: 'json',<br />
data: person,<br />
success: function (data, textStatus, xhr) {<br />
console.log(data);<br />
},<br />
error: function (xhr, textStatus, errorThrown) {<br />
console.log('Error in Operation');<br />
}<br />
});<br />
<br />
<br />
});<br />
});<br />
</script><br />
<br />
Name :- <input type="text" name="name" id="name" /><br />
Surname:- <input type="text" name="surname" id="surname" /><br />
<input type="button" id="Save" value="Save Data" /><br />
<br />
<br />
<br />
public IEnumerable<string> Get()<br />
{<br />
return new string[] { "value1", "value2" };<br />
}</div>
Anonymoushttp://www.blogger.com/profile/12091988898339694270noreply@blogger.com0tag:blogger.com,1999:blog-2466151865599682287.post-87109912274179379112016-07-19T10:38:00.003-07:002016-07-19T10:38:28.095-07:00<div dir="ltr" style="text-align: left;" trbidi="on">
<div data-WRID="WRID-146894924273191428" data-widgetType="productBanner" data-class="affiliateAdsByFlipkart" height="240px" width="120px"></div><script async src="//affiliate.flipkart.com/affiliate/widgets/FKAffiliateWidgets.js"></script></div>
Anonymoushttp://www.blogger.com/profile/12091988898339694270noreply@blogger.com0tag:blogger.com,1999:blog-2466151865599682287.post-90341974602591679422016-07-19T10:38:00.001-07:002016-07-19T10:38:01.031-07:00<div dir="ltr" style="text-align: left;" trbidi="on">
<div data-WRID="WRID-146894924273191428" data-widgetType="productBanner" data-class="affiliateAdsByFlipkart" height="240px" width="120px"></div><script async src="//affiliate.flipkart.com/affiliate/widgets/FKAffiliateWidgets.js"></script></div>
Anonymoushttp://www.blogger.com/profile/12091988898339694270noreply@blogger.com0tag:blogger.com,1999:blog-2466151865599682287.post-74677305097381424992016-06-28T09:20:00.000-07:002016-06-28T09:20:07.458-07:00Fill dataset using stored procedure in .Net<div dir="ltr" style="text-align: left;" trbidi="on">
// Within the code body set your variable <br />
string connectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;<br />
DataSet ds = new DataSet();<br />
try<br />
{<br />
string query = "exec GetData '" + FromDate + "','" + ToDate + "'";<br />
using (SqlConnection connection = new SqlConnection(connectionString))<br />
using (SqlCommand command = new SqlCommand(query, connection))<br />
using (SqlDataAdapter adapter = new SqlDataAdapter(command))<br />
{<br />
adapter.Fill(ds);<br />
}<br />
return ds;<br />
<br />
}<br />
catch<br />
{<br />
return ds;<br />
}</div>
Anonymoushttp://www.blogger.com/profile/12091988898339694270noreply@blogger.com1tag:blogger.com,1999:blog-2466151865599682287.post-85189904626162049252016-06-07T10:19:00.000-07:002016-06-07T10:19:37.941-07:00How to replace single quote with double quote<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: "arial" , "helvetica" , sans-serif;">In C#</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif;"> strComment = ""Manoj tyagi's photo;</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> strComment = strComment.Replace("'", "''");</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif;">In Sql :</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif;">EX 1</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<br />
<pre class="lang-sql prettyprint prettyprinted"><code><span style="font-family: "arial" , "helvetica" , sans-serif;"><span class="pln"></span><span class="kwd">DECLARE</span><span class="pln"> </span><span class="pun">@</span><span class="pln">sql varchar</span><span class="pun">(</span><span class="pln">max</span><span class="pun">)</span><span class="pln">
</span><span class="kwd">SET</span><span class="pln"> </span><span class="pun">@</span><span class="pln">sql </span><span class="pun">=</span><span class="pln"> </span><span class="str">' INSERT INTO '</span><span class="pln"> </span><span class="pun">+</span><span class="pln"> </span><span class="pun">@</span><span class="pln">tempTablea </span><span class="pun">+</span><span class="pln">
</span><span class="str">' SELECT 0 as TypeA, 0 as TypeB, '</span><span class="pln"> </span><span class="pun">+</span><span class="pln"> </span><span class="str">''''</span><span class="pun">+</span><span class="pln">
replace</span><span class="pun">(</span><span class="pln"> </span><span class="pun">@</span><span class="pln">name </span><span class="pun">,</span><span class="str">''''</span><span class="pun">,</span><span class="str">''''''</span><span class="pun">)+</span><span class="str">''''</span><span class="pun">+</span><span class="str">' as Name
FROM #tempTableb tt2'</span></span></code></pre>
<pre class="lang-sql prettyprint prettyprinted"><code><span class="str"><span style="font-family: "arial" , "helvetica" , sans-serif;">
</span></span></code></pre>
<pre class="lang-sql prettyprint prettyprinted"><span style="font-family: "arial" , "helvetica" , sans-serif;">Ex 2</span></pre>
<pre class="lang-sql prettyprint prettyprinted"><span style="font-family: "arial" , "helvetica" , sans-serif;">
</span></pre>
<pre class="lang-sql prettyprint prettyprinted"><code><span style="font-family: "arial" , "helvetica" , sans-serif;"><span class="kwd">UPDATE</span><span class="pln"> myTable1
</span><span class="kwd">SET</span><span class="pln"> myField1 </span><span class="pun">=</span><span class="pln"> REPLACE</span><span class="pun">(</span><span class="pln">myField1</span><span class="pun">,</span><span class="pln"> </span><span class="str">''''</span><span class="pun">,</span><span class="pln"> </span><span class="str">'"'</span><span class="pun">);</span></span></code></pre>
</div>
Anonymoushttp://www.blogger.com/profile/12091988898339694270noreply@blogger.com0tag:blogger.com,1999:blog-2466151865599682287.post-42985655739178682922016-06-06T11:38:00.005-07:002016-06-06T11:38:58.017-07:00What is cursor and how to use in sql server?<div dir="ltr" style="text-align: left;" trbidi="on">
<b>Cursor: </b>Cursor is basically a database object to retrieve data row by from resultset. cursor is used to loop through a resultset.<br />
<br />
Steps to use cursor:<br />
<br />
declare @studentid int<br />
<br />
<b>1. Declare Cursor-</b><br />
<br />
DECLARE @MyCursor CURSOR<br />
<br />
<b>2. Set Cursor</b><br />
<br />
SET @MyCursor = CURSOR FAST_FORWARD<br />
FOR<br />
select studentid from tbl_students<br />
<br />
<b>3.Open Cursor</b><br />
<br />
OPEN @MyCursor<br />
FETCH NEXT FROM @MyCursor<br />
INTO @studentid<br />
WHILE @@FETCH_STATUS = 0<br />
<br />
WHILE @@FETCH_STATUS = 0//loop till last row<br />
<br />
BEGIN<br />
query you want to execute<br />
END<br />
<b><br /></b>
<b>4. Close Cursor</b><br />
<br />
CLOSE @MyCursor<br />
<br />
<b>5. Deallocate Cursor</b><br />
<br />
DEALLOCATE @MyCursor</div>
Anonymoushttp://www.blogger.com/profile/12091988898339694270noreply@blogger.com0tag:blogger.com,1999:blog-2466151865599682287.post-55063643729184014362016-06-06T10:52:00.003-07:002016-06-06T10:52:35.659-07:00How to create non clustered index<div dir="ltr" style="text-align: left;" trbidi="on">
<b><u><span style="font-size: large;">Create Clustered Index</span></u></b><br />
<br />
/*<br />
USE [your db name]<br />
GO<br />
CREATE NONCLUSTERED INDEX [<Name of Missing Index, sysname,>]<br />
ON [dbo].[table_name] ([column1],[column1])<br />
INCLUDE ([column1],[column1],[column1])<br />
GO</div>
Anonymoushttp://www.blogger.com/profile/12091988898339694270noreply@blogger.com0tag:blogger.com,1999:blog-2466151865599682287.post-80969328189525075992016-06-06T10:47:00.003-07:002016-06-06T10:49:57.481-07:00How to check dead lock process id and kill that blocking process in sql server database<div dir="ltr" style="text-align: left;" trbidi="on">
<b>Query to check blocking process in sql server.</b><br />
<b><br /></b>
SELECT<br />
sp.spid<br />
, sp.blocked AS BlockingProcess<br />
, DB_NAME(sp.dbid) AS DatabaseName<br />
, sp.loginame,sp.cpu<br />
, CAST(text AS VARCHAR(1000)) AS SqlStatement<br />
FROM sys.sysprocesses sp<br />
CROSS APPLY sys.dm_exec_sql_text (sp.sql_handle) order by BlockingProcess desc,sqlstatement<br />
<b><br /></b>
<b>Kill blocking process</b><br />
<b><br /></b>
Kill 20 and execute</div>
Anonymoushttp://www.blogger.com/profile/12091988898339694270noreply@blogger.com0tag:blogger.com,1999:blog-2466151865599682287.post-69257715621440795012015-07-16T02:39:00.001-07:002015-07-16T02:39:32.004-07:00Code to send email from Gmail in .net<div dir="ltr" style="text-align: left;" trbidi="on">
private void SendEmail(string emailBody)<br /> {<br /> try<br /> {<br /> MailMessage message = new MailMessage();<br /><br /> //SmtpClient smtp = new SmtpClient();<br /><br /> message.From = new MailAddress(ConfigurationManager.AppSettings["FROMEMAIL"].ToString());<br /><br /> message.To.Add(new MailAddress(emailTo));<br /><br /> message.CC.Add(new MailAddress(emailCC));<br /><br /> message.Subject = emailSubject;<br /><br /> message.Body = emailBody.ToString();<br /><br /> message.IsBodyHtml = true;<br /><br /> var client = new SmtpClient("smtp.gmail.com", 587)<br /> {<br /> Credentials = new NetworkCredential(ConfigurationManager.AppSettings["FROMEMAIL"].ToString(), ConfigurationManager.AppSettings["FROMPWD"].ToString()),<br /> EnableSsl = true<br /> };<br /> client.Send(message);<br /> }<br /> catch (Exception ex)<br /> {<br /> objLogWriter.LogWrite(ex.Message);<br /> }<br /> }</div>
Anonymoushttp://www.blogger.com/profile/12091988898339694270noreply@blogger.com0tag:blogger.com,1999:blog-2466151865599682287.post-35277093857138281932015-07-16T02:26:00.000-07:002015-07-16T02:28:06.462-07:00Execute Stored Procedure with parameters and Fill Dataset<div dir="ltr" style="text-align: left;" trbidi="on">
<b>Introcution:</b> Here you can call and execute stored procedure from code behind and pass the parameters and fill dataset.<br />
<br />
<b>Implementation:</b><br />
DataSet ds = new DataSet();<br />
<br />
DataTable dt;<br />
<br />
sb.Append("<table>");<br />
<br />
try<br />
{<br />
using (SqlConnection connection = new SqlConnection(connectionString))<br />
{<br />
<br />
using (SqlCommand command = new SqlCommand("sp_DistwiseDetails1", connection))<br />
{<br />
command.CommandType = CommandType.StoredProcedure;<br />
<br />
command.Parameters.Add("@RetriveType", SqlDbType.VarChar).Value = 2;<br />
<br />
command.Parameters.Add("@FromDate", SqlDbType.VarChar).Value = DateTime.Now.AddYears(-2);<br />
<br />
command.Parameters.Add("@ToDate", SqlDbType.VarChar).Value = DateTime.Now.ToShortDateString();<br />
<br />
using (SqlDataAdapter adapter = new SqlDataAdapter(command))<br />
{<br />
adapter.Fill(ds);<br />
}<br />
<br />
}<br />
}<br />
dt = ds.Tables[0];<br />
}<br />
catch<br />
{<br />}</div>
Anonymoushttp://www.blogger.com/profile/12091988898339694270noreply@blogger.com0tag:blogger.com,1999:blog-2466151865599682287.post-2942299933800688502015-07-06T23:54:00.001-07:002015-07-07T05:59:00.446-07:00SQL Server Database Queries Part 1<div dir="ltr" style="text-align: left;" trbidi="on">
<b>Select Statement</b>:<br />
<br />
<span style="color: #cc0000;">select * from Subjects;</span><br />
<br />
<b>Aliasing Column Name:</b><br />
you can rename column according to your need using AS keyword.<br />
<span style="color: #cc0000;">select subjectname as subject from subjects;</span><br />
<br />
<b> </b><br />
<b>Eliminating duplicate records:(Distinct Clause)</b><br />
you can eliminate duplicate records using DISTINCT Keyword from resultset.<br />
<span style="color: #cc0000;">Select distinct subjectname from subjects;</span><br />
<br />
<b>Filtering Data(Where Clause):</b><br />
<br />
you can filter data using WHERE clause with some condition,<br />
<span style="color: #cc0000;">Select subject;name from subjects where subjectid=3;</span><br />
<span style="color: #cc0000;">Select subject;name from subjects where subjectid>3;</span><br />
<br />
<br />
<b> </b><br />
<b>The 'Not' Clause:</b><br />
<br />
you can use NOT keyword condition <br />
<span style="color: #cc0000;">Select subjectname from subjects where subjectname IS NOT NULL;</span><br />
<span style="color: #cc0000;">SELECT SUBJECTNAME FROM SUBJECTS WHERE SUBJECTID NOT IN (2,3); </span><br />
<br />
<b>Filtering String:</b><br />
you can filter string using LIKE keyword and %.<br />
'H%' will return all the records start with 'H'.<br />
'%H' will return all the records end with 'H'.<br />
'%H%' will return all the records start and end with 'H'.<br />
<span style="color: #cc0000;"><br /></span>
<span style="color: #cc0000;">Select subjectname from subject where name like('H%')<b> </b> ;</span><br />
<span style="color: #cc0000;"> </span><b> </b><br />
<b>The In and Between Keywords:</b><br />
<br />
you can use IN clause when you have multiple ids you can get all records which are IN();<br />
<span style="color: #cc0000;">select * from subjects where subjectid in (2,3);</span><br />
<br />
<span style="color: #cc0000;"><span style="color: black;">you can user BETWEEN clause when you want to get records between some range.</span> </span><br />
<span style="color: #cc0000;"><b> </b></span><br />
<span style="color: #cc0000;">select * from subjects where subjectid BETWEEN 2 and 3;</span><br />
<br />
<b>Sorting Data(Order By Clause):</b><br />
you can sort resultset using ORDER BY clause.<br />
<span style="color: #cc0000;">select * from subjects ORDER BY subjectname;</span><b> </b><br />
<b><br /></b>
<b>Limiting Records(Top Clause):</b><br />
<br />
you can limit records by using TOP clause in your query.<br />
<span style="color: #cc0000;">select TOP 2 * from subjects ORDERBY subjectname;</span><br />
<br />
<b>OFFSET FETCH:</b><br />
<br />
you can use OFFSET to keep and skip records. It is useful in paging concept.<br />
<span style="color: #cc0000;">SELECT * FROM SUBJECTS OFFSET 10 ROWS FETCH NEXT 25 ROWS ONLY;<b> </b></span><br />
<br />
<b>AGGREGATING DATA; GROUP BY AND HAVING CLAUSE</b><br />
you can use GROUP BY clause to get record set in Group.<br />
<span style="color: #cc0000;">SELECT COUNT(*) FROM SUBJECTS GROUP BY SUBJECTNAME;</span><b> </b><br />
<br />
<b>Select from multiple tables (Using Joins)</b><br />
<br />
Joins are very useful when you want to get data from multiple tables.<br />
<span style="color: #cc0000;">select * from subjects , books;</span><br />
<span style="color: #cc0000;"><b> </b></span><br />
<span style="color: #cc0000;">select a.subjectname,b.bookname from subjects a, books b where a.SubjectID=b.Subject;</span><br />
<br />
There are different type of joins in sql.<br />
<br />
<b>Cross Join:</b><br />
<br />
It will return Carthesian Product.<b> </b> <br />
<br />
<span style="color: #cc0000;">select * from books CROSS JOIN subjects;</span><br />
<br />
<b>Inner Join:</b><br />
<br />
It is the most useful join. It is optional to use Inner Keyword. It is used in place of where and is a<br />
proper way of join. it will return all the matching rows based on conditon.<br />
<br />
<span style="color: #cc0000;">select * from subjects INNER JOIN BOOKS ON SUBJECTS.SUBJECTID=BOOKS.SUBJECT;</span><br />
<br />
<b>Outer Join:</b><br />
<br />
Outer joins are used when we want to matching and unmatching data from tables. it is of two types.<br />
<br />
<b>Left Outer Join:</b><br />
<br />
It returns all matching of left and all of right records.<br />
<br />
<b> </b><br />
<span style="color: #cc0000;">SELECT * FROM SUBJECTS LEFT OUTER JOIN BOOKS ON SUBJECTS.SUBJECTID=BOOKS.SUBJECT;</span><br />
<br />
<b>Right Outer Join:</b><br />
<br />
It return all record of left and matching of right.<br />
<br />
<span style="color: #cc0000;">SELECT * FROM SUBJECTS Right OUTER JOIN BOOKS ON SUBJECTS.SUBJECTID=BOOKS.SUBJECT; </span><br />
<br />
<b>Ranking Functions:</b><br />
<b> </b> <br />
<b> </b>There are four ranking functions in sql server.<br />
<ol style="text-align: left;">
<li>ROW_NUMBER</li>
<li>RANK</li>
<li>DENSE_RANK</li>
<li>NTILE </li>
</ol>
ROW_NUMBER simply select the no of current row.<br />
RANK and DENSE_RANK assisgn unique number to each row.<br />
RANK return total no of rows of same rank plus 1.<br />
DENSE_RANK return rank plus 1. <br />
<b> </b><br />
<b> </b><br />
<b> </b></div>
Anonymoushttp://www.blogger.com/profile/12091988898339694270noreply@blogger.com0tag:blogger.com,1999:blog-2466151865599682287.post-56077835204928575532015-06-29T03:28:00.000-07:002015-06-29T03:28:35.376-07:00Uploading files with Asp.net MVC<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: Arial,Helvetica,sans-serif;"><span style="font-size: large;"><b>Uploading a single File:</b></span></span><br />
<span style="font-family: Arial,Helvetica,sans-serif;"><span style="font-size: large;">Start with view having a form that will postback to the current action</span></span><br />
<span style="font-family: Arial,Helvetica,sans-serif;"><span style="font-size: large;"><br /></span></span>
<pre><span style="font-family: Arial,Helvetica,sans-serif;"><span style="font-size: large;"><code class="language-csharp" data-lang="csharp"><span class="p"><</span><span class="n">form</span> <span class="n">action</span><span class="p">=</span><span class="s">""</span> <span class="n">method</span><span class="p">=</span><span class="s">"post"</span> <span class="n">enctype</span><span class="p">=</span><span class="s">"multipart/form-data"</span><span class="p">></span>
<span class="p"><</span><span class="n">label</span> <span class="k">for</span><span class="p">=</span><span class="s">"file"</span><span class="p">></span><span class="n">Filename</span><span class="p">:</</span><span class="n">label</span><span class="p">></span>
<span class="p"><</span><span class="n">input</span> <span class="n">type</span><span class="p">=</span><span class="s">"file"</span> <span class="n">name</span><span class="p">=</span><span class="s">"file1"</span> <span class="n">id</span><span class="p">=</span><span class="s">"file1"</span> <span class="p">/></span>
<span class="p"><</span><span class="n">input</span> <span class="n">type</span><span class="p">=</span><span class="s">"submit"</span> <span class="p">/></span>
<span class="p"></</span><span class="n">form</span><span class="p">></span></code></span></span></pre>
<pre><span style="font-family: Arial,Helvetica,sans-serif;"><span style="font-size: large;"><code class="language-csharp" data-lang="csharp"><span class="p"> </span></code></span></span></pre>
<pre><span style="font-family: Arial,Helvetica,sans-serif;"><span style="font-size: large;"><b><code class="language-csharp" data-lang="csharp"><span class="p">In Controller</span></code></b></span></span></pre>
<pre><span style="font-family: Arial,Helvetica,sans-serif;"><span style="font-size: large;"><code class="language-csharp" data-lang="csharp"><span class="p"> </span></code></span></span></pre>
<pre><span style="font-family: Arial,Helvetica,sans-serif;"><span style="font-size: large;"><code class="language-csharp" data-lang="csharp"><span class="p"><code class="language-csharp" data-lang="csharp"><span class="na">[HttpPost]</span>
<span class="k">public</span> <span class="n">ActionResult</span> <span class="nf">Index</span><span class="p">(</span><span class="n">HttpPostedFileBase</span> <span class="n">file</span><span class="p">1)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">file1</span><span class="p">.</span><span class="n">ContentLength</span> <span class="p">></span> <span class="m">0</span><span class="p">)</span> <span class="p">{</span>
<span class="kt">var</span> <span class="n">fileName</span> <span class="p">=</span> <span class="n">Path</span><span class="p">.</span><span class="n">GetFileName</span><span class="p">(</span><span class="n">file1</span><span class="p">.</span><span class="n">FileName</span><span class="p">);</span>
<span class="kt">var</span> <span class="n">path</span> <span class="p">=</span> <span class="n">Path</span><span class="p">.</span><span class="n">Combine</span><span class="p">(</span><span class="n">Server</span><span class="p">.</span><span class="n">MapPath</span><span class="p">(</span><b><span class="s">"~/App_Data/uploads"</span></b><span class="p">),</span> <span class="n">fileName</span><span class="p">);</span>
<span class="n">file</span><span class="p">1.</span><span class="n">SaveAs</span><span class="p">(</span><span class="n">path</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">return</span> <span class="nf">RedirectToAction</span><span class="p">(</span><span class="s">"Index"</span><span class="p">);</span>
<span class="p">}</span></code> </span></code></span></span></pre>
<pre><span style="font-family: Arial,Helvetica,sans-serif;"><span style="font-size: large;"><code class="language-csharp" data-lang="csharp"><span class="p">
</span></code></span></span></pre>
<pre><span style="font-family: Arial,Helvetica,sans-serif;"><span style="font-size: large;">
<code class="language-csharp" data-lang="csharp"><span class="p"><code class="language-csharp" data-lang="csharp"><b><span class="s">"~/App_Data/uploads" </span></b><span class="s">is a folder to upload files on</span><span class="s"> server.</span></code></span></code></span></span></pre>
<pre><span style="font-family: Arial,Helvetica,sans-serif;"><span style="font-size: large;"><code class="language-csharp" data-lang="csharp"><span class="p"><code class="language-csharp" data-lang="csharp"><span class="s"> </span></code></span></code></span></span></pre>
<pre><span style="font-family: Arial,Helvetica,sans-serif;"><span style="font-size: large;"><b><code class="language-csharp" data-lang="csharp"><span class="p"><code class="language-csharp" data-lang="csharp"><span class="s">Uploading multiple files: </span></code></span></code></b></span></span></pre>
<pre><span style="font-family: Arial,Helvetica,sans-serif;"><span style="font-size: large;"><b><code class="language-csharp" data-lang="csharp"><span class="p"><code class="language-csharp" data-lang="csharp"><span class="s">
</span></code></span></code></b></span></span></pre>
<pre><span style="font-family: Arial,Helvetica,sans-serif;"><span style="font-size: large;"><b>In view </b></span></span></pre>
<pre><span style="font-family: Arial,Helvetica,sans-serif;"><span style="font-size: large;">
<code class="language-csharp" data-lang="csharp"><span class="p"><</span><span class="n">form</span> <span class="n">action</span><span class="p">=</span><span class="s">""</span> <span class="n">method</span><span class="p">=</span><span class="s">"post"</span> <span class="n">enctype</span><span class="p">=</span><span class="s">"multipart/form-data"</span><span class="p">></span>
<span class="p"><</span><span class="n">label</span> <span class="k">for</span><span class="p">=</span><span class="s">"file1"</span><span class="p">></span><span class="n">File name</span><span class="p">:</</span><span class="n">label</span><span class="p">></span>
<span class="p"><</span><span class="n">input</span> <span class="n">type</span><span class="p">=</span><span class="s">"file"</span> <span class="n">name</span><span class="p">=</span><span class="s">"files1"</span> <span class="n">id</span><span class="p">=</span><span class="s">"file1"</span> <span class="p">/></span>
<span class="p"><</span><span class="n">label</span> <span class="k">for</span><span class="p">=</span><span class="s">"file2"</span><span class="p">></span><span class="n">File name</span><span class="p">:</</span><span class="n">label</span><span class="p">></span>
<span class="p"><</span><span class="n">input</span> <span class="n">type</span><span class="p">=</span><span class="s">"file"</span> <span class="n">name</span><span class="p">=</span><span class="s">"files1"</span> <span class="n">id</span><span class="p">=</span><span class="s">"file2"</span> <span class="p">/></span>
<span class="p"><</span><span class="n">input</span> <span class="n">type</span><span class="p">=</span><span class="s">"submit"</span> <span class="p">/></span>
<span class="p"></</span><span class="n">form</span><span class="p">></span></code></span></span></pre>
<pre><span style="font-family: Arial,Helvetica,sans-serif;"><span style="font-size: large;"><code class="language-csharp" data-lang="csharp"><span class="p"> </span></code></span></span></pre>
<pre><span style="font-family: Arial,Helvetica,sans-serif;"><span style="font-size: large;"><code class="language-csharp" data-lang="csharp"><span class="p">In Controller:</span></code></span></span></pre>
<pre><span style="font-family: Arial,Helvetica,sans-serif;"><span style="font-size: large;"><code class="language-csharp" data-lang="csharp"><span class="p"> </span></code></span></span></pre>
<pre><span style="font-family: Arial,Helvetica,sans-serif;"><span style="font-size: large;"><code class="language-csharp" data-lang="csharp"><span class="p"><code class="language-csharp" data-lang="csharp"><span class="na">[HttpPost]</span>
<span class="k">public</span> <span class="n">ActionResult</span> <span class="nf">Index</span><span class="p">(</span><span class="n">IEnumerable</span><span class="p"><</span><span class="n">HttpPostedFileBase</span><span class="p">></span> <span class="n">files</span><span class="p">)</span> <span class="p">{</span>
<span class="k">foreach</span> <span class="p">(</span><span class="kt">var</span> <span class="n">file</span>1 <span class="k">in</span> <span class="n">files</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">file1</span><span class="p">.</span><span class="n">ContentLength</span> <span class="p">></span> <span class="m">0</span><span class="p">)</span> <span class="p">{</span>
<span class="kt">var</span> <span class="n">fileName</span> <span class="p">=</span> <span class="n">Path</span><span class="p">.</span><span class="n">GetFileName</span><span class="p">(</span><span class="n">file1</span><span class="p">.</span><span class="n">FileName</span><span class="p">);</span>
<span class="kt">var</span> <span class="n">path</span> <span class="p">=</span> <span class="n">Path</span><span class="p">.</span><span class="n">Combine</span><span class="p">(</span><span class="n">Server</span><span class="p">.</span><span class="n">MapPath</span><span class="p">(</span><span class="s">"~/App_Data/uploads"</span><span class="p">),</span> <span class="n">fileName</span><span class="p">);</span>
<span class="n">file</span><span class="p">1.</span><span class="n">SaveAs</span><span class="p">(</span><span class="n">path</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">return</span> <span class="nf">RedirectToAction</span><span class="p">(</span><span class="s">"Index"</span><span class="p">);</span>
<span class="p">}</span></code> </span></code></span></span></pre>
<pre><span style="font-family: Arial,Helvetica,sans-serif;"><span style="font-size: large;"><code class="language-csharp" data-lang="csharp"><span class="p">Here we are getting list of files so we are using IEnumerable to list the files.</span></code></span></span></pre>
<pre><span style="font-family: Arial,Helvetica,sans-serif;"><span style="font-size: large;"><code class="language-csharp" data-lang="csharp"><span class="p">So you can upload multiples files on server.</span></code></span></span></pre>
</div>
Anonymoushttp://www.blogger.com/profile/12091988898339694270noreply@blogger.com0tag:blogger.com,1999:blog-2466151865599682287.post-77243058122442475602015-06-15T06:02:00.000-07:002015-06-15T06:02:33.577-07:00Abstraction in OOPS C#<div dir="ltr" style="text-align: left;" trbidi="on">
Abstraction: Abstraction is to hiding the complexity of object and showing the essential features of that object. It focus on what object can do instead of how it can do.<br />
"Abstraction is to hiding the working style of an object and showing the information of an object as understandable manner"<br />
<br />
Real world example of Abstraction:<br />
<br />
Suppose we take example of Mobile phones.<br />
<br />
<span style="font-family: Segoe UI; font-size: x-small;">Nokia 2710 (Features: Calling, SMS)<br />Nokia 3110 (Features: Calling, SMS, FM Radio, MP3, Camera)</span><br />
<br />
<span style="font-family: Segoe UI; font-size: x-small;">Abstract information(All mobile phones makes a
call to any number and can send SMS)</span><br />
<br />
<span style="font-family: Segoe UI; font-size: x-small;">for that you have to make a abstract class:</span><br />
<br />
<span style="color: blue; font-family: Segoe UI;"><span style="font-size: x-small;">abstract</span></span><span style="font-family: Segoe UI;"><span style="font-size: x-small;"> <span style="color: blue;">class</span> </span><span style="color: #2b91af;"><span style="font-size: x-small;">MobilePhone</span></span></span><br />
<div class="MsoNormal" style="font-family: Calibri,sans-serif; line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: Segoe UI;"><span style="font-size: x-small;"> {</span></span></div>
<div class="MsoNormal" style="font-family: Calibri,sans-serif; line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: Segoe UI;"><span style="font-size: x-small;"> <span style="color: blue;">public</span> <span style="color: blue;">void</span> Calling();</span></span></div>
<div class="MsoNormal" style="font-family: Calibri,sans-serif; line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: Segoe UI;"><span style="font-size: x-small;"> <span style="color: blue;">public</span> <span style="color: blue;">void</span> SendSMS();</span></span></div>
<div class="MsoNormal" style="font-family: Calibri,sans-serif; line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: Segoe UI;"><span style="font-size: x-small;"> }</span></span></div>
<div class="MsoNormal" style="font-family: Calibri,sans-serif; line-height: normal; margin: 0in 0in 0pt;">
<br /></div>
<div class="MsoNormal" style="font-family: Calibri,sans-serif; line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: Segoe UI;"><span style="font-size: x-small;"><span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">Nokia2710</span> : </span><span style="color: #2b91af;"><span style="font-size: x-small;">MobilePhone</span></span></span></div>
<div class="MsoNormal" style="font-family: Calibri,sans-serif; line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: Segoe UI;"><span style="font-size: x-small;"> {</span></span></div>
<div class="MsoNormal" style="font-family: Calibri,sans-serif; line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: Segoe UI;"><span style="font-size: x-small;"> <span style="color: blue;">public</span> <span style="color: blue;">void</span> FMRadio();</span></span></div>
<div class="MsoNormal" style="font-family: Calibri,sans-serif; line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: Segoe UI;"><span style="font-size: x-small;"> <span style="color: blue;">public</span> <span style="color: blue;">void</span> MP3();</span></span></div>
<div class="MsoNormal" style="font-family: Calibri,sans-serif; line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: Segoe UI;"><span style="font-size: x-small;"> <span style="color: blue;">public</span> <span style="color: blue;">void</span> Camera();</span></span></div>
<div class="MsoNormal" style="font-family: Calibri,sans-serif; line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: Segoe UI;"><span style="font-size: x-small;"> }</span></span></div>
<div class="MsoNormal" style="font-family: Calibri,sans-serif; line-height: normal; margin: 0in 0in 0pt;">
<br /></div>
<div class="MsoNormal" style="font-family: Calibri,sans-serif; line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: Segoe UI;"><span style="font-size: x-small;"> <span style="color: blue;">public</span> <span style="color: blue;">class</span> </span></span><span style="font-family: Segoe UI;"><span style="font-size: x-small;"><span style="color: #2b91af;">Nokia3110</span> </span></span><span style="font-family: Segoe UI;"><span style="font-size: x-small;">: </span><span style="color: #2b91af;"><span style="font-size: x-small;">MobilePhone</span></span></span></div>
<div class="MsoNormal" style="font-family: Calibri,sans-serif; line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: Segoe UI;"><span style="font-size: x-small;"> {</span></span></div>
<div class="MsoNormal" style="font-family: Calibri,sans-serif; line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: Segoe UI;"><span style="font-size: x-small;"> <span style="color: blue;">public</span> <span style="color: blue;">void</span> FMRadio();</span></span></div>
<div class="MsoNormal" style="font-family: Calibri,sans-serif; line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: Segoe UI;"><span style="font-size: x-small;"> <span style="color: blue;">public</span> <span style="color: blue;">void</span> MP3();</span></span></div>
<div class="MsoNormal" style="font-family: Calibri,sans-serif; line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: Segoe UI;"><span style="font-size: x-small;"> <span style="color: blue;">public</span> <span style="color: blue;">void</span> Camera();</span></span></div>
<div class="MsoNormal" style="font-family: Calibri,sans-serif; line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: Segoe UI;"><span style="font-size: x-small;"> <span style="color: blue;">public</span> <span style="color: blue;">void</span> Recording();</span></span></div>
<div class="MsoNormal" style="font-family: Calibri,sans-serif; line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: Segoe UI;"><span style="font-size: x-small;"> <span style="color: blue;">public</span> <span style="color: blue;">void</span> ReadAndSendEmails();</span></span></div>
<div class="MsoNormal" style="font-family: Calibri,sans-serif; font-size: 11pt; line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: Segoe UI;"><span style="font-size: x-small;"> }</span></span><span style="font-family: Segoe UI; font-size: x-small;"><br /></span></div>
<div class="MsoNormal" style="font-family: Calibri,sans-serif; line-height: normal; margin: 0in 0in 0pt;">
<br /></div>
</div>
Anonymoushttp://www.blogger.com/profile/12091988898339694270noreply@blogger.com0tag:blogger.com,1999:blog-2466151865599682287.post-30462444773598120572015-06-15T05:05:00.000-07:002015-06-15T05:05:33.410-07:00Introduction to object oriented programing in C#<div dir="ltr" style="text-align: left;" trbidi="on">
Class: A class is a blue print of an object that contains members and functions in it.<br />
<br />
for ex:<br />
<br />
class A<br />
{<br />
int a;<br />
string s;<br />
public void int sum(int a, int b<br />
{<br />}<br />}<br />
<br />
Object:An object is a instance of a class. You can create object of a class and access all the public variable and methods of that class.<br />
<br />
for ex:<br />
<br />
A objA=new Obj A();<br />
int sum=a.sum(a,b);</div>
Anonymoushttp://www.blogger.com/profile/12091988898339694270noreply@blogger.com0tag:blogger.com,1999:blog-2466151865599682287.post-48094459748938214992015-05-26T07:52:00.000-07:002015-05-26T07:52:44.418-07:00What is Xaml?<div dir="ltr" style="text-align: left;" trbidi="on">
XAML stands for extensible Application markup language, is variant of xml describing GUI. In winforms GUI framework was created in same language that you would use for interacting with the GUI like vb.net or c#.net.</div>
Anonymoushttp://www.blogger.com/profile/12091988898339694270noreply@blogger.com0tag:blogger.com,1999:blog-2466151865599682287.post-64668028720108973542015-05-10T01:28:00.001-07:002015-05-10T01:28:14.008-07:00Hello World in WPF- WPF Tutorial<div dir="ltr" style="text-align: left;" trbidi="on">
In xaml:<br />
<br />
<span style="font-family: Arial,Helvetica,sans-serif;"><Window x:Class="WpfApplication1.MainWindow"</span><br style="font-family: Arial,Helvetica,sans-serif;" /><span style="font-family: Arial,Helvetica,sans-serif;"> xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"</span><br style="font-family: Arial,Helvetica,sans-serif;" /><span style="font-family: Arial,Helvetica,sans-serif;"> xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"</span><br style="font-family: Arial,Helvetica,sans-serif;" /><span style="font-family: Arial,Helvetica,sans-serif;"> Title="MainWindow" Height="350" Width="525"></span><br style="font-family: Arial,Helvetica,sans-serif;" /><span style="font-family: Arial,Helvetica,sans-serif;"> <Grid></span><br style="font-family: Arial,Helvetica,sans-serif;" /><span style="font-family: Arial,Helvetica,sans-serif;"> <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="60">Hello World</TextBlock></span><br style="font-family: Arial,Helvetica,sans-serif;" /><span style="font-family: Arial,Helvetica,sans-serif;"> </Grid></span><br style="font-family: Arial,Helvetica,sans-serif;" /><span style="font-family: Arial,Helvetica,sans-serif;"></Window></span><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiaNtp3MSOOYiCVyF7YoJv4Fz_6MP5i74LD9qwlY5oLbiZIIXg66TCU-4i3Z-iA_R95Ba6niRwjyLQStKYQoiHfDN3b0dLMHQOmQLjA_3DThZqv8Ow_aGZzEfPDMTNyykyFfhlNHBeiVvM9/s1600/wpfhello.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="114" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiaNtp3MSOOYiCVyF7YoJv4Fz_6MP5i74LD9qwlY5oLbiZIIXg66TCU-4i3Z-iA_R95Ba6niRwjyLQStKYQoiHfDN3b0dLMHQOmQLjA_3DThZqv8Ow_aGZzEfPDMTNyykyFfhlNHBeiVvM9/s320/wpfhello.png" width="320" /></a></div>
After run program<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiTrwLZzJiqtL8pkZmpJH9G0V-YX5vByRDGHTddxp1-ThLn1aOUJaxDc9WSM8kaKLWWWbhvd8MvwHXpFqOxy5KuzkPxkJAY7ZqUClzga7eEgL3Ufvs7P-40PC6ffZThL7sCRVD7lyLJSYpw/s1600/wpfhello1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="179" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiTrwLZzJiqtL8pkZmpJH9G0V-YX5vByRDGHTddxp1-ThLn1aOUJaxDc9WSM8kaKLWWWbhvd8MvwHXpFqOxy5KuzkPxkJAY7ZqUClzga7eEgL3Ufvs7P-40PC6ffZThL7sCRVD7lyLJSYpw/s320/wpfhello1.png" width="320" /></a></div>
<br />
<br />
<br />
<br />
For more info visit:<br />
<a href="http://webxperts.co.in/" target="_blank">http://webxperts.co.in/</a><br />
<br />
<br /></div>
Anonymoushttp://www.blogger.com/profile/12091988898339694270noreply@blogger.com0tag:blogger.com,1999:blog-2466151865599682287.post-59694560696345750272015-05-10T01:12:00.002-07:002015-05-10T01:12:55.458-07:00Loop throuth all textboxes in Winforms<div dir="ltr" style="text-align: left;" trbidi="on">
For iterating through all textboxes in winforms:<br /><br />
<pre class="lang-cs prettyprint prettyprinted"><code><span class="kwd">foreach (TextBox TextBox in this.Controls.OfType<TextBox>())
{
if (TextBox.BackColor == Brushes.Green)
{
//your code
}
}</span></code><code><span class="pun"></span></code></pre>
</div>
Anonymoushttp://www.blogger.com/profile/12091988898339694270noreply@blogger.com0tag:blogger.com,1999:blog-2466151865599682287.post-31139278610257632442015-03-22T03:56:00.000-07:002015-03-22T03:56:39.203-07:00Design Patterns:Three layred or Tiered architechture<div dir="ltr" style="text-align: left;" trbidi="on">
This article will provide you the basic knowledge of Layered architecture.<br />
<b> </b><br />
<img alt="3 tier architecture" src="http://www.c-sharpcorner.com/UploadFile/4d9083/create-and-implement-3-tier-architecture-in-Asp-Net/Images/3%20tier%20architecture.jpg" /><b> </b><br />
<b>What is layer-</b> A layer is a reusable code that can be used any where, in any project.<br />
in .net a layer is setup as a project.<br />
We can have multiple layers to segregate our project.<br />
We are going to discuss three layered architecture here. in three layered architecture we have three layers:<br />
1.Data Access Layer<br />
2.Business Logic Layer<br />
3.Presentation Logic Layer<br />
<br />
<b>1.Data Access Layer(DAL)-</b> Data access layer is basically used to interact with database. We use ado.net to access database in this layer. BAL layer interact with DAL to interact with database. BAL call DAL function to send and receive data to database.<br />
<br />
2.<b>Business Access Layer(BAL)</b>-BAL layer is basically used to define business logic, calculations, conversions and all the stuff that is required by Presentation Layer.<br />
<br />
<b>3.Presentation Logic Layer- </b>This layer is basically used for user interface. Presentation layer always interact to BAL layer for any data required or to send any data to database.<br />
<br />
<b>Benifits of layered architecture:</b><br />
<b>1.</b>Easy to maintain of code. Because all layers are seperated from other so we can change to any layer easyily.<br />
<b>2.</b>Reusability of code: We can use the code anywhere in the same project or any other project using reference.<br />
3.Provide a segregated architecutre.</div>
Anonymoushttp://www.blogger.com/profile/12091988898339694270noreply@blogger.com0tag:blogger.com,1999:blog-2466151865599682287.post-49874194798409126402015-02-15T07:16:00.002-08:002015-02-15T07:16:43.337-08:00Ineterface with example in C#<div dir="ltr" style="text-align: left;" trbidi="on">
<b>Interface Definition:</b> An interface is basically a contract or service which will implemented by other classes.<br />
This implements the rules which will forced to use by derived classes.<br />
Interface has only declarations of methods and properties. They do not have body in method they<br />
have only the signatures.<br />
<b>Declaring Interfaces:</b><br />
<b><br /></b>
public interface IUser<br />
{<br />
void AddUser(User user);<br />
void EditUser(int Id)<br />
User GetUserByID(int Id);<br />
}<br />
<b>Implementation:</b><br />
<b><br /></b>
public class User:IUser<br />
{<br />
public User GetUserByID(int Id)<br />
{<br />
var context=...................;<br />
var user=context.Users.find(Id);<br />
return user;<br />
}<br />
public EditUser(int Id)<br />
{<br />
var context=...................;<br />
var user=context.Users.find(Id);<br />
context.Entry(user).State=EntityState.Modified;<br />
context.SaveChanges();<br />
}<br />
public void AddUser(User user)<br />
{<br />
var context=...................;<br />
context.Users.Add(user);<br />
context.SaveChanges();<br />
}<br />
}<br />
<br /></div>
Anonymoushttp://www.blogger.com/profile/12091988898339694270noreply@blogger.com0tag:blogger.com,1999:blog-2466151865599682287.post-17213691710472568882015-01-08T03:10:00.001-08:002015-01-08T03:10:11.636-08:00How to add all the rows of a column to string with comma seperated<div dir="ltr" style="text-align: left;" trbidi="on">
Introduction: Here we have to add all the rows of a column to string with comma seperated.<br />
Description:I am going to use coalesce function of sql server to achieve the result.<br />
Query:<br />
<br />
DECLARE @Names VARCHAR(8000) <br />SELECT @Names = COALESCE(@Names + ',', '') + Name <br />FROM tbl_Names<br />print @Names</div>
Anonymoushttp://www.blogger.com/profile/12091988898339694270noreply@blogger.com0tag:blogger.com,1999:blog-2466151865599682287.post-22567308866565267132014-12-29T01:52:00.000-08:002014-12-29T01:52:24.980-08:00How to call javascript and jquery function from code behind in ASP.net and c#<div dir="ltr" style="text-align: left;" trbidi="on">
<pre class="prettyprint prettyprinted"><span style="font-size: large;"><span style="font-family: "Courier New",Courier,monospace;"><span style="color: #0c343d;"><span class="typ">Introduction: Here I will tell you how you can call javascript and jquery function </span></span></span></span></pre>
<pre class="prettyprint prettyprinted"><span style="font-size: large;"><span style="font-family: "Courier New",Courier,monospace;"><span style="color: #0c343d;"><span class="typ">from codebehind.</span></span></span></span></pre>
<pre class="prettyprint prettyprinted"><span style="font-size: large;"><span style="font-family: "Courier New",Courier,monospace;"><span style="color: #0c343d;"><span class="typ">Descirption:</span>
<span class="typ">Here I will tell you how you can call javascript and jquery function </span><span class="typ">from codebehind.</span></span></span></span></pre>
<pre class="prettyprint prettyprinted"><span style="font-size: large;"><span style="font-family: "Courier New",Courier,monospace;"><span style="color: #0c343d;"><span class="typ">If you are using scriptmanager on page then you can call</span></span></span></span></pre>
<pre class="prettyprint prettyprinted"><span style="font-size: large;"><span style="font-family: "Courier New",Courier,monospace;"><span style="color: #0c343d;"><span class="typ">ScriptManager instance.</span></span></span></span></pre>
<pre class="prettyprint prettyprinted"><span style="font-size: large;"><span style="font-family: "Courier New",Courier,monospace;"><span style="color: #0c343d;"><span class="typ">If you are not using script manager then you can call </span></span></span></span></pre>
<pre class="lang-cs prettyprint prettyprinted"><span style="font-size: large;"><span style="font-family: "Courier New",Courier,monospace;"><span style="color: #0c343d;"><code><span class="pln"></span><span class="typ">Page</span><span class="pun">.</span><span class="typ">ClientScript instance</span></code></span></span></span></pre>
<span style="font-size: large;"><span style="font-family: "Courier New",Courier,monospace;"><span style="color: #0c343d;"><br /></span></span></span><pre class="lang-cs prettyprint prettyprinted"><span style="font-size: large;"><span style="font-family: "Courier New",Courier,monospace;"><span style="color: #0c343d;"><b><code><span class="pun">Implementation:</span></code></b></span></span></span></pre>
<pre class="lang-cs prettyprint prettyprinted"><span style="font-size: large;"><span style="font-family: "Courier New",Courier,monospace;"><span style="color: #0c343d;"><code><span class="pun">In Code Behind </span></code></span></span></span></pre>
<pre class="lang-cs prettyprint prettyprinted"><span style="font-size: large;"><span style="font-family: "Courier New",Courier,monospace;"><span style="color: #0c343d;"><code><span class="pun"><code><span class="kwd">protected</span><span class="pln"> </span><span class="kwd">void</span><span class="pln"> </span><span class="typ">MyButton_Click</span><span class="pun">(</span><span class="kwd">object</span><span class="pln"> sender</span><span class="pun">,</span><span class="pln"> </span><span class="typ">EventArgs</span><span class="pln"> e</span><span class="pun">)</span><span class="pln">
</span><span class="pun">{</span><span class="pln">
</span><span class="typ"></span></code></span></code><code><span class="pun"><code><span class="typ"><code><span class="typ">Page</span><span class="pun">.</span><span class="typ">ClientScript</span><span class="pun">.</span><span class="typ">RegisterStartupScript</span><span class="pun">(</span><span class="kwd">this</span><span class="pun">.</span><span class="typ">GetType</span><span class="pun">(),</span><span class="pln"> </span><span class="str">"myScript"</span><span class="pun">,</span><span class="pln"> </span></code></span></code></span></code></span></span></span></pre>
<pre class="lang-cs prettyprint prettyprinted"><span style="font-size: large;"><span style="font-family: "Courier New",Courier,monospace;"><span style="color: #0c343d;"><code><span class="pun"><code><span class="typ"><code><span class="pln"> </span><span class="str">"MyFunction</span></code><code><span class="str">();"</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">true</span><span class="pun">);</span></code></span><span class="pln">
</span><span class="pun">}</span></code> </span></code></span></span></span></pre>
<pre class="lang-cs prettyprint prettyprinted"><span style="font-size: large;"><span style="font-family: "Courier New",Courier,monospace;"><span style="color: #0c343d;">
<code><span class="pun"><code><span class="kwd">protected</span><span class="pln"> </span><span class="kwd">void</span><span class="pln"> </span><span class="typ">MyButton_Click</span><span class="pun">(</span><span class="kwd">object</span><span class="pln"> sender</span><span class="pun">,</span><span class="pln"> </span><span class="typ">EventArgs</span><span class="pln"> e</span><span class="pun">)</span><span class="pln">
</span><span class="pun">{</span><span class="pln">
</span><span class="typ"></span></code></span></code><code><span class="pun"><code><span class="typ"><code><span class="typ">ScriptManager</span><span class="pun">.</span><span class="typ">RegisterStartupScript</span><span class="pun">(</span><span class="kwd">this</span><span class="pun">.</span><span class="typ">GetType</span><span class="pun">(),</span><span class="pln"> </span><span class="str">"myScript"</span><span class="pun">,</span><span class="pln"> </span></code></span></code></span></code></span></span></span></pre>
<pre class="lang-cs prettyprint prettyprinted"><span style="font-size: large;"><span style="font-family: "Courier New",Courier,monospace;"><span style="color: #0c343d;"><code><span class="pun"><code><span class="typ"><code><span class="pln"> </span></code></span></code></span></code><code><span class="pun"><code><span class="typ"><code><span class="pln"> </span><span class="str">"</span></code></span></code></span></code><code><span class="pun"><code><span class="typ"><code><span class="str"><code><span class="pun"><code><span class="typ"><code><span class="str">MyFunction</span></code><code><span class="str"></span></code></span></code></span></code></span></code><code><span class="str">();"</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">true</span><span class="pun">);</span></code></span><span class="pln">
</span><span class="pun">}</span></code> </span></code></span></span></span></pre>
</div>
Anonymoushttp://www.blogger.com/profile/12091988898339694270noreply@blogger.com0tag:blogger.com,1999:blog-2466151865599682287.post-61375335006172986112014-12-28T05:44:00.000-08:002014-12-28T05:44:03.307-08:00Abstract classes in C#.NET, VB.NET<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="color: #0c343d; font-family: Courier New, Courier, monospace;"><b>Introduction:</b> Abstract classes are those classes that can not be instantiated, but they can be inherited by </span><br />
<span style="color: #0c343d; font-family: Courier New, Courier, monospace;">other classes.</span><br />
<span style="color: #0c343d; font-family: Courier New, Courier, monospace;"><b>Description: </b>Abstract classes are those classes that can not be instantiated, but they can be inherited by </span><br />
<span style="color: #0c343d; font-family: Courier New, Courier, monospace;">other classes. Abstract classes are base classes and inherited classes are called derived classes.</span><br />
<span style="color: #0c343d; font-family: Courier New, Courier, monospace;">Abstract class can have both abstract and non abstract method in it. </span><br />
<span style="color: #0c343d; font-family: Courier New, Courier, monospace;">When to use: It is use to give common functionality to all inherited classes. it works like a base class.</span><br />
<b><span style="color: #0c343d; font-family: Courier New, Courier, monospace;">Implementation:</span></b><br />
<span style="color: #0c343d; font-family: Courier New, Courier, monospace;"><span class="pln" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">abstract </span><span class="kwd" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">class</span><span class="pln" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;"> My</span><span class="typ" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">Shapes</span></span><br />
<span style="color: #0c343d; font-family: Courier New, Courier, monospace;"><span class="pun" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">{</span><span class="pln" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;"> </span></span><br />
<span style="color: #0c343d; font-family: Courier New, Courier, monospace;"><span class="pln" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">abstract </span><span class="kwd" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">public</span><span class="pln" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;"> </span><span class="typ" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">int</span><span class="pln" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;"> My</span><span class="typ" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">Area</span><span class="pun" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">();</span></span><br />
<span style="font-size: 14px; font-weight: bold; line-height: 24px; text-align: justify; white-space: pre-wrap;"><span style="color: #0c343d; font-family: Courier New, Courier, monospace;">}</span></span><br />
<span style="color: #0c343d; font-family: Courier New, Courier, monospace;"><span class="kwd" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">class</span><span class="pln" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;"> </span><span class="typ" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">Square</span><span class="pln" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;"> </span><span class="pun" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">:</span><span class="pln" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;"> </span><span class="pln" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">My</span><span class="typ" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">Shapes</span></span><br />
<span class="pun" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;"><span style="color: #0c343d; font-family: Courier New, Courier, monospace;">{</span></span><br />
<span style="color: #0c343d; font-family: Courier New, Courier, monospace;"><span class="pln" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;"> </span><span class="typ" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">int</span><span class="pln" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;"> side </span><span class="pun" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">=</span><span class="pln" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;"> </span><span class="lit" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">0</span><span class="pun" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">;</span></span><br />
<span style="color: #0c343d; font-family: Courier New, Courier, monospace;"><span class="pln" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;"> </span><span class="kwd" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">public</span><span class="pln" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;"> </span><span class="typ" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">Square</span><span class="pun" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">(</span><span class="typ" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">int</span><span class="pln" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;"> n</span><span class="pun" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">)</span></span><br />
<span style="color: #0c343d; font-family: Courier New, Courier, monospace;"><span class="pln" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;"> </span><span class="pun" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">{</span><span class="pln" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;"> </span></span><br />
<span style="color: #0c343d; font-family: Courier New, Courier, monospace;"><span class="pln" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">side </span><span class="pun" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">=</span><span class="pln" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;"> n</span><span class="pun" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">;</span><span class="pln" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;"> </span></span><br />
<span class="pun" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;"><span style="color: #0c343d; font-family: Courier New, Courier, monospace;">}</span></span><br />
<span style="color: #0c343d; font-family: Courier New, Courier, monospace;"><span class="pln" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;"> </span><span class="com" style="box-sizing: border-box; font-size: 14px; font-style: italic; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">// Override Area method</span></span><br />
<span style="color: #0c343d; font-family: Courier New, Courier, monospace;"><span class="kwd" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">public</span><span class="pln" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;"> override </span><span class="typ" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">int</span><span class="pln" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;"> </span><span class="pln" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">My</span><span class="typ" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">Area</span><span class="pun" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">()</span></span><br />
<span style="color: #0c343d; font-family: Courier New, Courier, monospace;"><span class="pun" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">{</span><span class="pln" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;"> </span></span><br />
<span style="color: #0c343d; font-family: Courier New, Courier, monospace;"><span class="kwd" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">return</span><span class="pln" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;"> side </span><span class="pun" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">*</span><span class="pln" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;"> side</span><span class="pun" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">;</span><span class="pln" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;"> </span></span><br />
<span class="pun" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;"><span style="color: #0c343d; font-family: Courier New, Courier, monospace;">}</span></span><br />
<span style="font-size: 14px; font-weight: bold; line-height: 24px; text-align: justify; white-space: pre-wrap;"><span style="color: #0c343d; font-family: Courier New, Courier, monospace;">}</span></span><br />
<span style="color: #0c343d; font-family: Courier New, Courier, monospace;"><span class="kwd" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">class</span><span class="pln" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;"> </span><span class="typ" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">Rectangle</span><span class="pln" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;"> </span><span class="pun" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">:</span><span class="pln" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;"> </span><span class="pln" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">My</span><span class="typ" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">Shapes</span></span><br />
<span class="pun" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;"><span style="color: #0c343d; font-family: Courier New, Courier, monospace;">{</span></span><br />
<span style="color: #0c343d; font-family: Courier New, Courier, monospace;"><span class="typ" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">int</span><span class="pln" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;"> length </span><span class="pun" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">=</span><span class="pln" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;"> </span><span class="lit" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">0</span><span class="pun" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">,</span><span class="pln" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;"> width</span><span class="pun" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">=</span><span class="lit" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">0</span><span class="pun" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">;</span></span><br />
<span style="color: #0c343d; font-family: Courier New, Courier, monospace;"><span class="kwd" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">public</span><span class="pln" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;"> </span><span class="typ" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">Rectangle</span><span class="pln" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;"> </span><span class="pun" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">(</span><span class="typ" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">int</span><span class="pln" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;"> length</span><span class="pun" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">,</span><span class="pln" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;"> </span><span class="typ" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">int</span><span class="pln" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;"> width</span><span class="pun" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">)</span></span><br />
<span class="pun" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;"><span style="color: #0c343d; font-family: Courier New, Courier, monospace;">{</span></span><br />
<span style="color: #0c343d; font-family: Courier New, Courier, monospace;"><span class="kwd" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">this</span><span class="pun" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">.</span><span class="pln" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">length </span><span class="pun" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">=</span><span class="pln" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;"> length</span><span class="pun" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">;</span></span><br />
<span style="color: #0c343d; font-family: Courier New, Courier, monospace;"><span class="kwd" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">this</span><span class="pun" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">.</span><span class="pln" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">width </span><span class="pun" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">=</span><span class="pln" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;"> width</span><span class="pun" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">;</span></span><br />
<span class="com" style="box-sizing: border-box; font-size: 14px; font-style: italic; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;"><span style="color: #0c343d; font-family: Courier New, Courier, monospace;">// Override Area method </span></span><br />
<span style="color: #0c343d; font-family: Courier New, Courier, monospace;"><span class="kwd" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">public</span><span class="pln" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;"> override </span><span class="typ" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">int</span><span class="pln" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;"> </span><span class="pln" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">My</span><span class="typ" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">Area</span><span class="pun" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">()</span></span><br />
<span style="color: #0c343d; font-family: Courier New, Courier, monospace;"><span class="pun" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">{</span><span class="pln" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;"> </span></span><br />
<span style="color: #0c343d; font-family: Courier New, Courier, monospace;"><span class="kwd" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">return</span><span class="pln" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;"> length </span><span class="pun" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">*</span><span class="pln" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;"> width</span><span class="pun" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;">;</span><span class="pln" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;"> </span></span><br />
<span class="pun" style="box-sizing: border-box; font-size: 14px; font-weight: bold; line-height: 24px; margin: 0px; text-align: justify; vertical-align: top; white-space: pre-wrap;"><span style="color: #0c343d; font-family: Courier New, Courier, monospace;">}</span></span><br />
<span style="font-size: 14px; font-weight: bold; line-height: 24px; text-align: justify; white-space: pre-wrap;"><span style="color: #0c343d; font-family: Courier New, Courier, monospace;">}</span></span></div>
Anonymoushttp://www.blogger.com/profile/12091988898339694270noreply@blogger.com0tag:blogger.com,1999:blog-2466151865599682287.post-46762970474894584012014-12-04T03:04:00.001-08:002014-12-04T04:02:02.284-08:00Call web method from page using jquery and ajax without postback<div dir="ltr" style="text-align: left;" trbidi="on">
<b>Introduction: </b>In this article I will show you how to call webmethod from aspx page using jquery<br />
and ajax without postback.<br />
<br />
<b>Description: </b>Call webmethod from aspx page using jquery and ajax without postback.<b> </b><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjPrT_ETg3w6TTfvCtHAVvmDhOUPY3t8OdH5CAYYRRbMb2UzqnR1tzP3mVgGkOw3ghcsQOcJnHDeBN8IxLyqTfDkfWkkmr6bvZiO9HPauj5KVWQsg7DMQ0B50TI_8t8bpJjmhe_yM-sF4L4/s1600/WebMethodCall.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjPrT_ETg3w6TTfvCtHAVvmDhOUPY3t8OdH5CAYYRRbMb2UzqnR1tzP3mVgGkOw3ghcsQOcJnHDeBN8IxLyqTfDkfWkkmr6bvZiO9HPauj5KVWQsg7DMQ0B50TI_8t8bpJjmhe_yM-sF4L4/s1600/WebMethodCall.png" height="143" width="320" /></a></div>
<br />
<br />
<b>In Aspx Page:</b><br />
<br />
<span style="background-color: #0c343d;"><span style="background-color: white;"><span style="color: #0c343d;"><head runat="server"><br /> <title></title><br /><script src="scripts/jquery-1.3.2.min.js" type="text/javascript"></script><br /><script type = "text/javascript"><br />function ShowTime() {<br /> $.ajax({<br /> type: "POST",<br /> url: "CS.aspx/GetTime",<br /> data: '{name: "' + $("#<%=txtName.ClientID%>")[0].value + '" }',<br /> contentType: "application/json; charset=utf-8",<br /> dataType: "json",<br /> success: OnSuccess,<br /> failure: function(response) {<br /> alert(response.d);<br /> }<br /> });<br />}<br />function OnSuccess(response) {<br /> alert(response.d);<br />}<br /></script> <br /></head></span></span></span><br />
<span style="color: #0c343d;"><span style="background-color: white;"><body style = "font-family:Arial; font-size:10pt"><br /><form id="form1" runat="server"><br /><div><br />Your Name : <br /><asp:TextBox ID="txtName" runat="server"></asp:TextBox><br /><input id="btnGetTime" type="button" value="Show Current Time" <br /> onclick = "ShowCurrentTime()" /><br /></div><br /></form><br /></body></span></span><br />
<br />
<b>In Code Behind:</b><br />
<br />
<span style="color: #0c343d;">[System.Web.Services.WebMethod]<br />public static string GetCurrentTime(string name)<br />{<br /> return "Hello " + name + Environment.NewLine + "The Current Time is: " <br /> + DateTime.Now.ToString();<br />}</span><br />
<br /></div>
Anonymoushttp://www.blogger.com/profile/12091988898339694270noreply@blogger.com0tag:blogger.com,1999:blog-2466151865599682287.post-74796792290739939602014-11-12T03:14:00.000-08:002014-11-12T03:14:14.125-08:00How to change SQL server database mode from single user to multiuser and multi user to single user<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-size: small;"><b>Introduction:</b> In this example you can set database mode to single user or multiuser</span><br />
<span style="font-size: small;"><br /></span>
<span style="font-size: small;"><b>Description:</b> Here you will see how to change database mode to single and multiuser.</span><br />
<span style="font-size: small;"><br /></span>
<b><span style="font-size: small;">Implementation:</span></b><br />
<br />
<span style="font-size: small;"><b>Set Multi User Mode to Single User Mode</b> </span><br />
<pre class="lang-sql prettyprint prettyprinted"><span style="font-size: small;"><code><span class="kwd"> </span></code></span></pre>
<pre class="lang-sql prettyprint prettyprinted"><span style="font-size: small;"><code><span class="kwd">USE</span><span class="pln"> MASTER</span><span class="pun">;</span><span class="pln">
GO
</span><span class="kwd">ALTER</span><span class="pln"> </span><span class="kwd">DATABASE</span><span class="pln"> </span><span class="pun">[</span><span class="pln">databasename</span><span class="pun">]</span><span class="pln"> </span><span class="kwd">SET</span><span class="pln"> SINGLE_USER</span></code></span></pre>
<pre class="lang-sql prettyprint prettyprinted"><span style="font-size: small;"><code><span class="pln"> </span></code></span></pre>
<pre class="lang-sql prettyprint prettyprinted"><span style="font-family: "Courier New",Courier,monospace;"><span style="font-size: small;"><code><span class="pln"><b>Set Single User Mode to Multi User Mode</b> </span></code></span></span></pre>
<pre class="lang-sql prettyprint prettyprinted"><span style="font-size: small;"><code><span class="pln">
</span></code></span></pre>
<pre class="lang-sql prettyprint prettyprinted"><span style="font-size: small;">
<code><span class="kwd">USE</span><span class="pln"> MASTER</span><span class="pun">;</span><span class="pln">
GO
</span><span class="kwd">ALTER</span><span class="pln"> </span><span class="kwd">DATABASE</span><span class="pln"> </span><span class="pun">[</span><span class="pln"></span></code><code><span class="pun"></span><span class="pln">databasename</span><span class="pun"></span></code><code><span class="pln"></span><span class="pun">]</span><span class="pln"> </span><span class="kwd">SET</span><span class="pln"> MULTI_USER</span></code></span></pre>
<pre class="lang-sql prettyprint prettyprinted"><code><span class="pln"> </span></code></pre>
<pre class="lang-sql prettyprint prettyprinted"><code><span class="pln"> </span></code></pre>
</div>
Anonymoushttp://www.blogger.com/profile/12091988898339694270noreply@blogger.com0