tag:blogger.com,1999:blog-91249088622597945862024-03-05T05:01:46.565-05:00.NET and BEYONDWeb Developer from New York posting his experiences in his small development world.Usman Suglatwalahttp://www.blogger.com/profile/07825248275790817551noreply@blogger.comBlogger51125tag:blogger.com,1999:blog-9124908862259794586.post-8816196029657607652015-06-02T15:14:00.001-04:002015-06-02T15:15:52.505-04:00Finding which event fired(button clicked) in Page_Load or Page_Init/Page_PreInit<div dir="ltr" style="text-align: left;" trbidi="on">
I was working on an app and I wanted to turn off Event Validations when a certain action was performed to Render the HTML. Keeping them on won't let me render my UserControl to an HTML file. So I wanted to capture the Event right in Page_PreInit so that I can disable Event Validation of Page. Note that this can only be done either programmatically before Page is Initialized, or as a Page directive in aspx file.<br />
<br />
Request.Form["__EVENTTARGET"] is the variable that will capture the information for the button clicked.<br />
<br />
One additional aspect to note is to have UseSubmitBehavior="false" for the Button Web Control to generate the value for "__EVENTTARGET".<br />
<br />
So in your html:<br />
<br />
<asp:Button runat="server" ID="btnDownload" UseSubmitBehavior="false" ClientIDMode="Static" Text="Download" style="display:none;" OnClick="btnDownload_Click" /><br />
<br />
In code behind, this is what you would have:<br />
<br />
<br />
<code class="cs">
protected void Page_PreInit(object sender, EventArgs e) </code><br />
<code class="cs"> { </code><br />
<code class="cs">if (Request.Form["__EVENTTARGET"] != null && Request.Form["__EVENTTARGET"].Contains("btnDownload"))<br />
Page.EnableEventValidation = false;//(NO INTELLISENSE!)disable event validation when the button is clicked for downloading file<br />
}
</code>
</div>
Usman Suglatwalahttp://www.blogger.com/profile/07825248275790817551noreply@blogger.com0tag:blogger.com,1999:blog-9124908862259794586.post-88636200054593883402015-05-15T06:00:00.000-04:002015-05-15T06:00:02.894-04:00Filtering/Grouping by multiple columns in sql subquery<div dir="ltr" style="text-align: left;" trbidi="on">
I have been struggling for a while to have multiple columns in subquery and then filtering out the result.<br />
<br />
Often with composite keys in the staging table, you want to check if there are any duplicates.<br />
<br />
Taking an example of a fictitious "sales" table:<br />
<br />
select * from sales where order_number in<br />
(select order_number from sales<br />
group by order_number, customer_id<br />
having count(*)>1)<br />
<br />
Above query might not give the desired results if I am looking for particular results with filters. The reason being I did not apply all the fields in the select query for the ones used in group by.<br />
<br />
An extensible solution below takes care of that:<br />
<br />
--Use CTE to store result for further filtering<br />
with cte as (select s1.field1, s1.field2, s1.field3 from sales as s1<br />
where exists<br />
--Have a subquery for multiple column grouping. Compare it with the fields of the parent query, which would yield 1 corresponding record<br />
(select s2.field1, s2.field2, sd.field3 from sales as s2<br />
where s2.field1=sd1.field1 and s2.field2=s1.field2 and sd.field3=s1.field3<br />
group by field1,field2,field3<br />
) --Have your extra condition here for filtering<br />
)<br />
select * from cte where reached_target='Y' -- Get all those qualified records needed<br />
<br />
In this case, Common Table Expression (CTE) does come in very handy to filter out the final resultset.</div>
Usman Suglatwalahttp://www.blogger.com/profile/07825248275790817551noreply@blogger.com0tag:blogger.com,1999:blog-9124908862259794586.post-57820698347512462652015-04-21T09:06:00.004-04:002015-04-21T09:11:20.963-04:00Defining and using Server variables in the html head section of page <div dir="ltr" style="text-align: left;" trbidi="on">
My browser was caching the javasscripts and css and it gets annoying when you are multiple design changes to code. So I decided to do cache busting. I defined a Random number variable in code behind and wanted to use it in html <head> so that every time a request is made, the browser takes it as a new request to the server with a fresh copy of styles and javascript files. The solution is a little quirky, but works:<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><link href="mystyle.css?rn=<%="" +Rand %>" type="text/css" rel="stylesheet"/><br />
<div>
<br /></div>
<div>
where:</div>
<div>
rn : is variable for Random Number</div>
<div>
Rand : is server side generated Random number</div>
<div>
<br /></div>
<div>
Considering the Random number generated as 1234, the output would be like below:</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span><link href="mystyle.css?rn=1234" type="text/css" rel="stylesheet"/></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
Note: Use this for development only. Caching is always good to have in production to speed up loading times. With any new build of css/javascript, a version number can be assigned to get a fresh copy.</div>
</div>
Usman Suglatwalahttp://www.blogger.com/profile/07825248275790817551noreply@blogger.com0tag:blogger.com,1999:blog-9124908862259794586.post-53537689805051920742013-10-23T11:11:00.004-04:002013-10-23T11:13:25.847-04:00Doing a LoC count in Visual Studio<div dir="ltr" style="text-align: left;" trbidi="on">
I just wanted to know how many lines of Code do I have in my Solution. Here's a nice trick posted by a fellow blogger that uses Regular Expressions. Way to go! Quick and Easy!<br />
<br />
<a href="http://blog.schuager.com/2009/01/line-count-in-visual-studio.html">http://blog.schuager.com/2009/01/line-count-in-visual-studio.html</a><br />
<br />
Basically, search for the Following Regex in the solution:<br />
<br />
<span style="background-color: #cccccc;"><span style="font-family: Courier New, Courier, monospace;"><span style="color: #333333; font-size: 13px; line-height: 18px; white-space: pre-wrap;"> ^~(:Wh</span><span class="variable" style="box-sizing: border-box; color: teal; font-size: 13px; line-height: 18px; white-space: pre-wrap;">@/</span><span style="color: #333333; font-size: 13px; line-height: 18px; white-space: pre-wrap;">/.+)~(:Wh</span><span class="variable" style="box-sizing: border-box; color: teal; font-size: 13px; line-height: 18px; white-space: pre-wrap;">@\</span><span style="color: #333333; font-size: 13px; line-height: 18px; white-space: pre-wrap;">{:Wh</span><span class="variable" style="box-sizing: border-box; color: teal; font-size: 13px; line-height: 18px; white-space: pre-wrap;">@)</span><span style="color: #333333; font-size: 13px; line-height: 18px; white-space: pre-wrap;">~(:Wh</span><span class="variable" style="box-sizing: border-box; color: teal; font-size: 13px; line-height: 18px; white-space: pre-wrap;">@\</span><span style="color: #333333; font-size: 13px; line-height: 18px; white-space: pre-wrap;">}:Wh</span><span class="variable" style="box-sizing: border-box; color: teal; font-size: 13px; line-height: 18px; white-space: pre-wrap;">@)</span><span style="color: #333333; font-size: 13px; line-height: 18px; white-space: pre-wrap;">~(:Wh</span><span class="variable" style="box-sizing: border-box; color: teal; font-size: 13px; line-height: 18px; white-space: pre-wrap;">@/</span><span class="comment" style="box-sizing: border-box; color: #999988; font-size: 13px; font-style: italic; line-height: 18px; white-space: pre-wrap;">#).+ </span></span></span></div>
Usman Suglatwalahttp://www.blogger.com/profile/07825248275790817551noreply@blogger.com0tag:blogger.com,1999:blog-9124908862259794586.post-16819679640149815782013-10-02T12:06:00.000-04:002013-10-23T11:16:09.144-04:00Using Razor syntax with Javascript<div dir="ltr" style="text-align: left;" trbidi="on">
Following approach was done to have the razor syntax in Javascript. Wrapping the javascript <text> with <text> does the job!</text><br />
<br />
<pre class="javascript" name="code">@if(Model!=null){
<text>"<span style="color: #76768d; font-size: 14px; font-weight: bold;">@Model.title</span>" +</text>
}
</pre>
<pre class="javascript" name="code"></pre>
<pre class="javascript" name="code"></pre>
<pre class="javascript" name="code"><span style="font-family: 'Times New Roman'; white-space: normal;">Although the code above looks like Razor syntax placed in HTML, this has been used in Javascript and works perfect!</span></pre>
</div>
Usman Suglatwalahttp://www.blogger.com/profile/07825248275790817551noreply@blogger.com0tag:blogger.com,1999:blog-9124908862259794586.post-80064376887752902482013-09-20T12:18:00.000-04:002013-09-20T12:18:39.456-04:00Using CKEditor in your MVC project <div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
CKEditor is an Amazing Rich Text Editor to be used in your MVC Applications. I had implemented that one of my forms and was bent over to implement it throughout the project, replacing the existing editor which was little buggy.<br />
<br />
Implementation has been made very easy with the release of the newer version of CKEditor 4<br />
<br />
First you need to use the HTMLHelpers to create a Text Area:<br />
<br />
<pre class="c#" name="code">@Html.TextArea("controlid", "controlvalue")
</pre>
<br />
Then place your CKEditor javascript script below the control. This will replace the TextArea with the Editor<br />
<br /></div>
<pre class="c#" name="javascript">CKEDITOR.replace('controlid', {
uiColor: '#808080',
height: '120px',
toolbar: [
['Bold', 'Italic', 'Underline', '-', 'NumberedList', 'BulletedList', '-', 'Link', 'Unlink', '-', 'Image', 'Table'],
['FontSize', 'TextColor', 'BGColor', 'Source'],
// ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock']
]
});
</pre>
<br />
<br />
Form submission is magically taken care of by MVC Approach on postback<br />
<br />
But all that was not plain and simple on Ajax based submissions. I had some trouble implementing it on one of the Ajax based forms. This is what I did based upon the CKEditor API<br />
the click of the submit button.<br />
<br />
<pre class="js" name="code">$(document).ready(function() {
$("#btnSubmit").click(function(){
$("#controlid").val(CKEDITOR.instances["controlid"].getData());
});
});
</pre>
<br />
And I had Success at last!<br />
<br /></div>
Usman Suglatwalahttp://www.blogger.com/profile/07825248275790817551noreply@blogger.com0tag:blogger.com,1999:blog-9124908862259794586.post-40421897344976008352013-08-07T12:55:00.000-04:002015-06-12T12:59:17.840-04:00Using Jquery and JQuery UI inside AJAX UpdatePanel<div dir="ltr" style="text-align: left;" trbidi="on">
I wanted to call a JQuery "alert" on the Click event of a button, which was also a Trigger to an Update Panel. My condition for the alert was in code behind. For those who experienced this, JQuery/javascript doesn't work nicely with UpdatePanel<br />
<br />
Searching on Google led me to the solution below and it works as expected!<br />
<br />
<blockquote class="tr_bq">
<span style="font-size: x-small;"><span style="font-family: Courier New, Courier, monospace;">protected void btnPrevious_Click(object sender, ImageClickEventArgs e)</span><span style="font-family: 'Courier New', Courier, monospace;">{ </span></span></blockquote>
<blockquote class="tr_bq">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> int curpageindex=-1;</span></blockquote>
<blockquote class="tr_bq">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> if ((int)ViewState["Pageindex"] > 0)</span></blockquote>
<blockquote class="tr_bq">
<span style="font-size: x-small;"><span style="font-family: Courier New, Courier, monospace;"> {</span> </span></blockquote>
<blockquote class="tr_bq">
<span style="font-family: 'Courier New', Courier, monospace;"><span style="font-size: x-small;"> //Your code</span></span></blockquote>
<blockquote class="tr_bq">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> BindData();</span></blockquote>
<blockquote class="tr_bq">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></blockquote>
<blockquote class="tr_bq">
<span style="font-size: x-small;"><span style="font-family: Courier New, Courier, monospace;"> else if ((int)ViewState["Pageindex"] == 0)</span> </span></blockquote>
<blockquote class="tr_bq">
<span style="font-size: x-small;"><span style="font-family: Courier New, Courier, monospace;"> <span style="background-color: #7f6000;">ScriptManager</span>.RegisterStartupScript([updatePanelId], this.GetType(), "click", "firstrecord();", true); </span><span style="font-family: 'Courier New', Courier, monospace;"> }</span></span></blockquote>
<blockquote class="tr_bq">
</blockquote>
Please bear in mind that ScriptManager is the Ajax ScriptManager that has different overloading Parameters, one of them being a reference to the UpdatePanel.<br />
<br />
<a href="https://www.stormconsultancy.co.uk/blog/development/code-snippets/execute-javascript-when-an-updatepanel-is-updated/" target="_blank">Here's</a> a nice explaination of how this works.<br />
<br /></div>
Usman Suglatwalahttp://www.blogger.com/profile/07825248275790817551noreply@blogger.com0tag:blogger.com,1999:blog-9124908862259794586.post-29680187942736141452013-06-03T13:49:00.000-04:002013-09-07T11:26:40.281-04:00Using Mercurial as a preferred Source Control<div dir="ltr" style="text-align: left;" trbidi="on">
I needed a Source Control to track changes in my projects, I have been hearing good things about Mercurial and its integration into Visual Studio 2010 with the tools like <a href="http://tortoisehg.bitbucket.org/" target="_blank">TortoiseHg</a> and <a href="http://visualhg.codeplex.com/" target="_blank">VisualHg</a>. Not to mention that Mercurial is an Open Source software and available for free download. Mercurial is a Distributed Version Source Control (DVCS) where each client has entire copy of the repository.<br />
<br />
Got a jump start on Installing and integrating Mercurial with a great video <a href="http://vimeo.com/46914510" target="_blank">here</a>, which shows all the installing as well as configuration process.<br />
<br />
Mercurial can be downloaded <a href="http://mercurial.selenic.com/" target="_blank">here</a>.<br />
<br />
Its fun to work with Mercurial using the Command line too, though the GUI does take care of your needs. Here's a neat list of commands to execute your changes:<br />
<br />
<a href="http://searchco.de/lists/list-of-mercurial-commands" target="_blank">http://searchco.de/lists/list-of-mercurial-commands</a><br />
<br />
One of the important commands that I would like to remember is in below example, which fetches me the changeset along with the filename. I can also specify the range of the changeset. In the example shown, the command will fetch the changes between the changesets 1 and 10.<br />
<br />
<pre class="sql" name="code">hg log --stat -r 1:10
</pre>
<br />
<br />
I also would like to include the .hgignore file which is quite handy for committing the changes to the repository.<br />
<br />
<pre class="sql" name="code"># use glob syntax
syntax: glob
*.obj
*.pdb
*.user
*.aps
*.pch
*.vspscc
*.vssscc
*_i.c
*_p.c
*.ncb
*.suo
*.tlb
*.tlh
*.bak
*.[Cc]ache
*.ilk
*.log
*.lib
*.sbr
*.scc
*.DotSettings
[Bb]in
[Dd]ebug*/**
obj/
[Rr]elease*/**
_ReSharper*/**
NDependOut/**
packages/**
[Tt]humbs.db
[Tt]est[Rr]esult*
[Bb]uild[Ll]og.*
*.[Pp]ublish.xml
*.resharper
*.ncrunch*
*.ndproj
</pre>
<br />
<br />
Enjoy!</div>
Usman Suglatwalahttp://www.blogger.com/profile/07825248275790817551noreply@blogger.com0tag:blogger.com,1999:blog-9124908862259794586.post-64794337747542003572013-05-08T12:00:00.000-04:002013-06-14T12:07:26.808-04:00Passing down a string with an apostrophe to javascript function<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
Its like back to Javascript 101, but sometimes its forgotton and takes up some time to identify whats wrong with the script. Thats what happened to me. I wasn't sure how would I parse my string. Finally got an answer.<br />
<br />
<pre class="html" name="code"><a href="javascript:void();" onclick="PopulateMyControl('@Server.HtmlDecode(Model.DESCRIPTION.Replace("'","\\'"))')"> Edit Content</a>
</pre>
</div>
<br />
The escape character takes care of the apostrophe, and the HtmlDecode takes care of any browser based compatibility issues</div>Usman Suglatwalahttp://www.blogger.com/profile/07825248275790817551noreply@blogger.com2tag:blogger.com,1999:blog-9124908862259794586.post-27993505977466796762013-04-16T13:32:00.000-04:002013-04-16T13:32:10.088-04:00Connecting to a Remote SQL Server and Import Data from your local SQL Server (2008 Express)<div dir="ltr" style="text-align: left;" trbidi="on">
I have a remote database sitting on VPS and I need to transfer the data to the remote server. All I do is first register/connect the remote Sql server in my Management Studio. For this, enter the provided server name using the registered domain name (or IP Address) along with the provided port number. Append the Sql server name (I appended \SQLExpress).<br />
<br />
Doing this will enable you to connect the remote server in your local management studio (assuming you enter the correct authentication details for username/password !).<br />
<br />
Before you go ahead with the next step of doing data migration, make sure first you run the database scripts so that your indexes/foreign keys are intact. Once this is done, you can use the import/export wizard to export data from your local machine to the remote server. A tiny trick is to use the import wizard from the destination database rather than using the export wizard from the source database. This will ensure your configuration for destination database is aptly configured.<br />
<br />
Sorry this is very bland write-up without any screenshots or proper explanation, but hopefully I'll provide them when I have more time.<br />
<br />
<br />
<br /></div>
Usman Suglatwalahttp://www.blogger.com/profile/07825248275790817551noreply@blogger.com0tag:blogger.com,1999:blog-9124908862259794586.post-66116459429746473882013-04-04T13:46:00.000-04:002013-04-04T13:46:08.214-04:00Profiler for SQL Express<div dir="ltr" style="text-align: left;" trbidi="on">
I have SQL Express currently installed on my machine. Since I am working on the "free" version, the package doesn't include SQL Profiler. I highly depend on SQL Profiler to trace down queries. What to do now?
Well, Google is my friend! I found this <a href="http://expressprofiler.codeplex.com/">utility</a>, available on Codeplex. Download and use it!
<br /></div>
Usman Suglatwalahttp://www.blogger.com/profile/07825248275790817551noreply@blogger.com0tag:blogger.com,1999:blog-9124908862259794586.post-80212240776321209472013-04-02T12:03:00.000-04:002013-04-12T12:24:38.435-04:00Links to Bookmark and Follow up<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: Arial, Helvetica, sans-serif;">Some Notes on Semantic Versioning. Follow up on this, Usman! </span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;"><a href="http://semver.org/" target="_blank">http://semver.org/</a></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">The World of Entity Framework :</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;"><a href="http://msdn.microsoft.com/en-US/data/ee712907">http://msdn.microsoft.com/en-US/data/ee712907</a></span><br />
<br />
<span style="font-family: Arial, Helvetica, sans-serif;">Entity Framework Version History :</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;"><a href="http://msdn.microsoft.com/en-us/data/jj574253">http://msdn.microsoft.com/en-us/data/jj574253</a></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-size: x-small;"><span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></span>
<span style="font-size: x-small;"><span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></span>
<br />
<span style="font-size: x-small;"><span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></span>
<br />
<br />
<br />
<br /></div>
Usman Suglatwalahttp://www.blogger.com/profile/07825248275790817551noreply@blogger.com0tag:blogger.com,1999:blog-9124908862259794586.post-70075519098217627752013-03-06T15:57:00.000-05:002013-09-13T16:02:09.081-04:00AJAX Caching issue in Internet Explorer (IE) 9 (way back upto IE 6)<div dir="ltr" style="text-align: left;" trbidi="on">
I had been pulling my hair apart for resolving the browser compatibility issue. My MVC App has been working well in other browsers, but while doing testing, I found a notorious issue in IE. I had been hung on this issue for several hours. Tried clearing history/cache.. No luck. Tried using the cache trough developer tools (F12)... No luck.. Tried resetting the Browser to its default installation, thinking I might have accidently clicked on a setting for the browser to malfunction... No luck! restarted the machine a couple of times.... But I guess I was looking at the wrong place. Doing a google search for the correct keywords might have helped in the first place! Further research led me to find that IE caches the AJAX requests while others don't. Thats actually BAD news for me, because that gives me inconsistency in data.<br />
<br />
<br />
Fellow internet geeks had posted a few solutions to overcome this issue:<br />
<br />
<a href="http://dougwilsonsa.wordpress.com/2011/04/29/disabling-ie9-ajax-response-caching-asp-net-mvc-3-jquery/">http://dougwilsonsa.wordpress.com/2011/04/29/disabling-ie9-ajax-response-caching-asp-net-mvc-3-jquery/</a><br />
<br />
<a href="http://www.dashbay.com/2011/05/internet-explorer-caches-ajax/">http://www.dashbay.com/2011/05/internet-explorer-caches-ajax/</a><br />
<br />
<a href="http://ivida.co.uk/2011/09/29/ie-9-ajax-request-caching-mvc/">http://ivida.co.uk/2011/09/29/ie-9-ajax-request-caching-mvc/</a><br />
<br />
<br />
<br />
<br />
This worked for me! Yay!<br />
<br />
<div class="line number1 index0 alt2" style="-webkit-box-shadow: none !important; background-color: white !important; background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: #444444; direction: ltr !important; float: none !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; font-size: 12px; height: auto !important; left: auto !important; line-height: 13.1875px; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px 1em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="jscript plain" style="-webkit-box-shadow: none !important; background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">$(document).ready(</code><code class="jscript keyword" style="-webkit-box-shadow: none !important; background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 102, 153) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; font-size: 1em !important; font-weight: bold !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">function</code><code class="jscript plain" style="-webkit-box-shadow: none !important; background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">() {</code></div>
<div class="line number2 index1 alt1" style="-webkit-box-shadow: none !important; background-color: white !important; background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: #444444; direction: ltr !important; float: none !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; font-size: 12px; height: auto !important; left: auto !important; line-height: 13.1875px; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px 1em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="jscript plain" style="-webkit-box-shadow: none !important; background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">$.ajaxSetup({ cache: </code><code class="jscript keyword" style="-webkit-box-shadow: none !important; background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 102, 153) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; font-size: 1em !important; font-weight: bold !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">false</code> <code class="jscript plain" style="-webkit-box-shadow: none !important; background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">});</code></div>
<div class="line number3 index2 alt2" style="-webkit-box-shadow: none !important; background-color: white !important; background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: #444444; direction: ltr !important; float: none !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; font-size: 12px; height: auto !important; left: auto !important; line-height: 13.1875px; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px 1em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="jscript plain" style="-webkit-box-shadow: none !important; background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">});</code><br />
<br /></div>
</div>
Usman Suglatwalahttp://www.blogger.com/profile/07825248275790817551noreply@blogger.com0New York, NY, USA40.7143528 -74.005973140.3291643 -74.65142010000001 41.0995413 -73.3605261tag:blogger.com,1999:blog-9124908862259794586.post-12164796649952236772013-03-01T09:43:00.000-05:002013-03-01T09:43:00.183-05:00Access the Log for the scheduled processes<div dir="ltr" style="text-align: left;" trbidi="on">
The log for the scheduled processes (to trace the failures) is available at:<br />
<br />
\\WINDIR\Tasks\SchedLgU.txt<br />
<br />
Other resources that I found on the web regarding this can be looked here:<br />
<br />
<a href="http://blogs.technet.com/b/rspitz/archive/2010/11/07/scheduled-tasks-appear-hung-in-the-running-state-on-windows-server-2003-based-systems.aspx">http://blogs.technet.com/b/rspitz/archive/2010/11/07/scheduled-tasks-appear-hung-in-the-running-state-on-windows-server-2003-based-systems.aspx</a><br />
<br />
Check the following link to increase the size of the file:
<br />
<a href="http://support.microsoft.com/kb/169443">http://support.microsoft.com/kb/169443</a>
</div>
Usman Suglatwalahttp://www.blogger.com/profile/07825248275790817551noreply@blogger.com0tag:blogger.com,1999:blog-9124908862259794586.post-53241934075246172882013-01-17T12:45:00.000-05:002013-04-22T12:47:26.686-04:00Using Heidi as MySql Client to connect to remote server<div dir="ltr" style="text-align: left;" trbidi="on">
I had to make some db modifications for one of my clients to the mysql database on the remote server. I hardly have any experience working on the php/mysql arena. Call it my lack of knowledge or understanding, but I had a hard time connecting to the remote server. I tried mysql workbench, but that would crash right when I went ahead to access the database. I was frustrated since I had to make one small change and it was sucking up my time. Then someone over the <a href="http://www.google.com/" target="_blank">internet</a> suggested <a href="http://www.heidisql.com/" target="_blank">HeidiSql</a>.<br />
<br />
Apart from being able to "connect successfully", HeidiSql is really fast and provides and great clean UI to manage your data. Point to be noted for future refs!!</div>
Usman Suglatwalahttp://www.blogger.com/profile/07825248275790817551noreply@blogger.com0tag:blogger.com,1999:blog-9124908862259794586.post-17421644005443262882012-11-26T12:19:00.000-05:002012-11-26T12:19:00.288-05:00Resolving the Validation of viewstate MAC failed error<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: inherit;">I have been receiving the following error on the page when I clicked on the link (in the Gridview) before the Page had fully loaded. </span>My Page has a Gridview which uses DataKeyNames. Additionally it had a lot of Javascript ads which slowed down loading of the Page.<br />
<span style="font-family: inherit;"><br />
<span style="color: red;">Validation of viewstate
MAC failed. If this application is hosted by a Web
Farm or cluster, ensure that configuration
specifies the same validationKey and validation
algorithm. AutoGenerate cannot be used in a cluster.
</span></span><br />
<span style="font-family: inherit;"><span style="color: red;"><br /></span></span>
<br />
<br />
<span style="font-family: inherit;"><span style="color: red;"><br /></span></span>
<span style="font-family: inherit;">On doing some research, I found out that the due to the use of GridView and the DataKeyNames, the Framework implements a ViewState Encryption Technique for keeping the data secure. Hence, when a link is clicked on a partial page load, the encryption tag might not have been rendered on the page, causing the page to crash. </span><br />
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;">I read <a href="http://blogs.msdn.com/b/tom/archive/2008/03/14/validation-of-viewstate-mac-failed-error.aspx" target="_blank">this</a> excellent post which aptly details the issue and its resolution.</span><br />
<br />
<span style="font-family: inherit;">Basically, it appears to be some sort of bug in the existing Framework and the blog posts a workaround.</span><br />
<br />
<span style="font-family: inherit;">I used Solution 3 since it still was keeping the Security aspects in place which executing the page elegantly. Basically what it did was to remove the Validation script right before the end of the form tag and place it after the beginning of the Tag. </span></div>
<pre name="code" class="c-sharp">
protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
System.IO.StringWriter stringWriter =
new System.IO.StringWriter();
HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter);
base.Render(htmlWriter);
string html = stringWriter.ToString();
string[] aspnet_formelems = new string[5];
aspnet_formelems[0] = "__EVENTTARGET";
aspnet_formelems[1] = "__EVENTARGUMENT";
aspnet_formelems[2] = "__VIEWSTATE";
aspnet_formelems[3] = "__EVENTVALIDATION";
aspnet_formelems[4] = "__VIEWSTATEENCRYPTED";
foreach (string elem in aspnet_formelems)
{
//Response.Write("input type=""hidden"" name=""" & abc.ToString & """")
int StartPoint = html.IndexOf("<input type=\"hidden\" name=\"" +
elem.ToString() + "\"");
if (StartPoint >= 0)
{
//does __VIEWSTATE exist?
int EndPoint = html.IndexOf("/>", StartPoint) + 2;
string ViewStateInput = html.Substring(StartPoint,
EndPoint - StartPoint);
html = html.Remove(StartPoint, EndPoint - StartPoint);
int FormStart = html.IndexOf("<form");
int EndForm = html.IndexOf(">", FormStart) + 1;
if (EndForm >= 0)
html = html.Insert(EndForm, ViewStateInput);
}
}
writer.Write(html);
}
</pre>Usman Suglatwalahttp://www.blogger.com/profile/07825248275790817551noreply@blogger.com0tag:blogger.com,1999:blog-9124908862259794586.post-7816482615669861462012-10-12T12:50:00.000-04:002012-10-12T14:40:38.297-04:00Hiding Tabs(MenuItem) in asp:Menu<div dir="ltr" style="text-align: left;" trbidi="on">
I was working on the asp:Menu where I have to hide a certain Tab if there is no content for it. This is what I did. I knew the index of the Tab that Had to be removed:<br />
<br />
<pre class="csharp" name="code">
//tabs_Menu is the id for asp:Menu
MenuItemCollection menuitems=tabs_Menu.Items;
menuitems.Remove(tabs_Menu.Items[1]);
</pre>
</div>
Usman Suglatwalahttp://www.blogger.com/profile/07825248275790817551noreply@blogger.com0tag:blogger.com,1999:blog-9124908862259794586.post-15176087589102062452012-07-16T13:22:00.001-04:002012-07-16T13:22:36.605-04:00Finding Duplicates and copying Excel formula to the end of data<div dir="ltr" style="text-align: left;" trbidi="on">
I have an excel file that has about 100,000 records. I wanted to find out the duplicates in a particular column before removing them. So I had to mark the rows with something as an identifier. Below is what I found for the formula. So essentially if the duplicates are in Column A, this formula should be placed in an empty column(or a new column):<br />
<br />
=IF(COUNTIF(A:A, A1)>1, "Duplicate !","")<br />
<br />
I had to apply this formula to all the 100,000 records, and someone over the internet posted a nice example of doing this:<br />
<br />
<a href="http://www.handyexceltips.com/2008/01/16/dragging-a-formula-down/">http://www.handyexceltips.com/2008/01/16/dragging-a-formula-down/</a>
<br />
<br />
Very useful in those time crunches !</div>Usman Suglatwalahttp://www.blogger.com/profile/07825248275790817551noreply@blogger.com0tag:blogger.com,1999:blog-9124908862259794586.post-88628080286551792742012-06-07T14:00:00.000-04:002012-06-07T14:00:41.835-04:00Batch Update using SQL<div dir="ltr" style="text-align: left;" trbidi="on">
Though this is a fairly easy process, its worth mentioning here since it is something which cannot be thought about.
Using top x in your query, you could basically choose how many records need to be updated. This is helpful for processing the records as required
<pre name="code" class="sql">
UPDATE top (100) TableName
SET
column1 = getdate(),
remarks = 'batch for API Upload'
where column2 is not null and column1 > '2012-1-1'
</pre>
<br /></div>Usman Suglatwalahttp://www.blogger.com/profile/07825248275790817551noreply@blogger.com0tag:blogger.com,1999:blog-9124908862259794586.post-34923099176257985622012-06-04T11:29:00.002-04:002012-06-04T11:33:01.491-04:00Extract Date from DateTime Field in SQL<div dir="ltr" style="text-align: left;" trbidi="on">
I was working on SQL to create a view to get the reports for our subscribers and group them by day. This is fairly easy to implement in .NET, but I have been licking SQL candies for a while and so wanted to try it out. This is how I did:
<pre class="sql" name="code"> SELECT DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE()))
</pre>
I could have used varchar converstion and "trimmed" the time value, but I had to further sort the resultset based upon the date obtained, so it was important for me to have it as a date type.
<br /></div>Usman Suglatwalahttp://www.blogger.com/profile/07825248275790817551noreply@blogger.com0tag:blogger.com,1999:blog-9124908862259794586.post-12926685553476366332012-05-12T15:18:00.000-04:002012-05-12T15:18:00.481-04:00Using Trim() in LINQ to SQL on an Empty string<div dir="ltr" style="text-align: left;" trbidi="on">
This is kind of a silly thing I did, now that I think about it, but I must admit I was ignorant.<br />
<br />
I didnt realize that you don't necessarily need a string utility to "Trim()" an Empty string of whitespaces, becuause, well, it doesn't matter.<br />
<br />
To SQL, ' ' is same as ' '.<br />
<br />
What I realized when using Trim() function, was this function was adding an overload of ltrim(rtrim(emptystringfield)) to my already resource intensive query, which in effect was increasing my query execution time. So use Trim() only when you need it, especially when using expensive queries.</div>Usman Suglatwalahttp://www.blogger.com/profile/07825248275790817551noreply@blogger.com0tag:blogger.com,1999:blog-9124908862259794586.post-12505870792873924262012-04-18T11:47:00.001-04:002012-04-18T11:48:28.020-04:00Searching for numeric character(s) in Column of a Table in SQLFor Reference:<br />
<br />
<pre name="code" class="Cpp">select * from [YourTable] where
patindex('%[0-9]%',[yourcolumn]) <> 0
</pre><br />
That was kinda easy!Usman Suglatwalahttp://www.blogger.com/profile/07825248275790817551noreply@blogger.com0tag:blogger.com,1999:blog-9124908862259794586.post-51705411627426998522012-03-23T11:56:00.000-04:002012-03-23T11:56:23.016-04:00Visual Studio ThemesI tweaked my IDE to have a black background v/s the default white, and also changed some other color schemes to have contrasting colors, but here's a website that gives you a good amount of cool themes to apply to. Check out the link below. I am going to try them soon!<br />
<br />
http://www.hanselman.com/blog/VisualStudioProgrammerThemesGallery.aspxUsman Suglatwalahttp://www.blogger.com/profile/07825248275790817551noreply@blogger.com0tag:blogger.com,1999:blog-9124908862259794586.post-18965934763542896802012-03-07T17:56:00.000-05:002012-03-07T17:56:00.090-05:00Deleting duplicate records using SQLI have been working on SQL lately and its worth mentioning in the blog as to how easily find and delete duplicate records in the database.<br />
<br />
Here's a nice solution posted by Pinal Dave on his blog:<br />
<a href=" http://blog.sqlauthority.com/2007/03/01/sql-server-delete-duplicate-records-rows/"><br />
http://blog.sqlauthority.com/2007/03/01/sql-server-delete-duplicate-records-rows/</a><br />
<br />
NJoy!Usman Suglatwalahttp://www.blogger.com/profile/07825248275790817551noreply@blogger.com0tag:blogger.com,1999:blog-9124908862259794586.post-24477416033475496792012-02-21T12:24:00.000-05:002012-04-25T16:24:18.641-04:00Maintaining Scrollbar postion of listBox inside of UpdatePanelI have this multiple selected ListBox where I would want to maintain the scroll position of the ListBox. This is how I did, following the instructions from the blog post <a href="http://basgun.wordpress.com/2008/06/09/maintain-scroll-position-updatepanel-postback/">here</a><br />
<br />
Please make sure this code is after the ScriptManager tag on the page:<br />
<pre name="code" class="js"><script type="text/javascript">
var xPos, yPos;
var prm = Sys.WebForms.PageRequestManager.getInstance();
function BeginRequestHandler(sender, args)
{
if ($get('<%=lstBoxName.ClientID %>') != null)
{
xPos = $get('<%=lstBoxName.ClientID %>').scrollLeft;
yPos = $get('<%=lstBoxName.ClientID %>').scrollTop;
}
}
function EndRequestHandler(sender, args)
{
if ($get('<%=lstBoxName.ClientID %>') != null) {
$get('<%=lstBoxName.ClientID %>').scrollLeft = xPos;
$get('<%=lstBoxName.ClientID %>').scrollTop = yPos;
}
}
prm.add_beginRequest(BeginRequestHandler);
prm.add_endRequest(EndRequestHandler);
</script>
</pre>Usman Suglatwalahttp://www.blogger.com/profile/07825248275790817551noreply@blogger.com1