Thursday, July 15, 2010

Cannot add duplicate collection entry of type 'add' with unique key attribute 'name' set to 'RewriteModule' - HTTP Error 500.19 - Internal Server Err

When I uploaded the site to the server, I got an HTTP Error 500.19 - Internal Server Error which says "Cannot add duplicate collection entry of type 'add' with unique key attribute 'name' set to 'RewriteModule'". Error was in the following line in web.config


I got the solution to change the application config file from the following link:
http://support.microsoft.com/kb/942055

But, hosting providers won't allow that on server.

I added the following under where the RewriteModule is added

Also, there were some virtual directory issues. Hosting provider
changed that. Now it is working.

Friday, July 9, 2010

Issue when using AsyncFileUpload control

4:14 AM Posted by Unknown , , No comments
I tried to use AsyncFileUpload control in a page. The AsyncFileUpload control was placed inside the first view of a multiview control. The page required a querystring parameter, and if the parameter is not present, the second view of the multiviewcontrol will be shown. This check is made on the Page Load event. This causes issue on the fileupload process. It was giving error, since on the postback, it gets another view. So, I did like this.

on the event "OnClientUploadStarted
", I gave a value to a hidden element, and on page load, a checking is made, to see, if the value is given for the hidden element. If the value is given, the view1 itself will be shown without checking the availability of querystring parameter.

Don't know if that is the correct method. Anyhow, it worked.

Wednesday, July 7, 2010

Tuesday, July 6, 2010

Generate sql script with data from database

11:39 PM Posted by Unknown No comments
How can we copy data as well the structure and schema as sql query? We need database publishing wizard for that.

Download the database publishing wizard.
It will be installed at following location : C:\Program Files\Microsoft SQL Server\90\Tools\Publishing\

run the exe and you can get the sql file with all the data, schema and structure of the database you select.

Thursday, July 1, 2010

Wednesday, May 19, 2010

System.Net.Mail.SmtpFailedRecipientException: Mailbox unavailable. The server response was: 5.7.1 Unable to relay

10:52 PM Posted by Unknown , No comments
I have got this issue many times, when I try to send email using smtp. There can be several causes for this. You have to allow relay for mail to be sent to outside servers like gmail.com. For sending mail within your server you don't have to do this. You can find some helps from the following links:
Help1
Help2
Help3

The code I have used is given below:

using System.Net.Mail;


SmtpClient smtpClient = new SmtpClient();
MailMessage message = new MailMessage();
smtpClient.Port = 25;
smtpClient.Host = "smtp.domain.com";
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = new System.Net.NetworkCredential("webmail username", "webmail password");
message.From = new MailAddress("webmail username");
message.To.Add("test@gmail.com");
string emailBody = "Hi,

Welcome

";
message.Body = emailBody;
message.Subject = "testing";
message.IsBodyHtml = true;
smtpClient.Send(message);

But, after making the changes on the server, as specified on the above links, I was still getting the same error. Then I added the following line in between the above code.
smtpClient.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;

Then the error was gone.

Friday, April 23, 2010

Wednesday, March 31, 2010

Grouping Gridview

7:31 PM Posted by Unknown No comments
Some times we want to group gridview. ZNet is a good control for this use.
ZNet
We can use this for grouping and also for the comparison.

Saturday, March 13, 2010

specifying ValidationGroup in Page_ClientValidate function

1:41 AM Posted by Unknown , No comments
Hi,

We know that, Page_ClientValidate function tests if all controls meet asp.net validation criteria. This function is provided by asp.net. But, if we use more than, one validation group in the page, we may have to specify the validation group, we want to validate. For that, give like given below:
Page_ClientValidate('ValGroupName')

Then, it will validate only for that validation group

Friday, March 5, 2010

The Controls collection cannot be modified because the control contains code blocks

10:26 AM Posted by Unknown No comments
This is a common error. It occurs when we use <%= %> tag inside the head tag with runat="server" given. You can get rid of the error by removing the runat="server" from the head tag. But, sometimes, we want to keep that. We can use <%# %> instead of <%= %>. But, then, the value may not get bound and we may not get the value of the expression. So, when we use <%# %>, we have to add Page.Header.DataBind(); in the Page Load event.
More Info

Wednesday, March 3, 2010

To access control of a User Control from an aspx page

9:44 AM Posted by Unknown No comments
Whenever you want to access the controls of an usercontrol, create public properties for those controls in your usercontrols and you could easily access them in your .aspx page.

Here it goes how...
UserControl.

1 public partial class WebUserControl : System.Web.UI.UserControl
2 {
3 public string TextBoxValue {
4 get { return TextBox1.Text; }
5 set { TextBox1.Text = value; }
6 }
7 protected void Page_Load(object sender, EventArgs e) {
8
9 }
10 }

In your .aspx page you can access it either html or code
<%@ Register TagPrefix="DS" TagName="TB" Src="~/WebUserControl.ascx" %>




or

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
myTB1.TextBoxValue = "Sample Text";
}
}

Friday, February 26, 2010

Monday, February 15, 2010

Thursday, February 4, 2010

Wednesday, February 3, 2010

Calling method of a usercontrol from another usercontrol

10:21 AM Posted by Unknown 1 comment
I need to call the method in a usercontrol from another usercontrol. Both controls are placed in same page.
If it is a web application, both controls will be in same namespace. So, we can get their names in the codebehind.

for eg.
if control1 is to be found from control2.
both control1 and control2 are in folder controls. webapplication name is test. So the namespace would be test.control2. Since, both these controls are under the same namespace, we can find the control2 in control1 and vice versa directly.
control2 2 = control1.FindControl("control21") as control2;

But, if this is a website, no namespace. So, we have to add a reference.
Add reference in control1 to find control2.
<%@ Reference Control="~/controls/control2" %>
then, in codebehind,
ASP.controls_control2 2 = this.FindControl("control21") as ASP.controls_control2;

Finding Controls

10:17 AM Posted by Unknown No comments
Check the name of the control in the rendered html. For eg.
I need to find gridview "grdwSelectedCandidates" in usercontrol "SelectedCandidates.ascx" which is inside the ajax tabpanel inside ajax tabcontainer.
I need to find this from another control which is placed in another tabpanel in the same container.
The rendered name is "ctl00_ContentPlaceHolder1_TabContainer1_TabPanel6_SelectedCandidates1_grdwSelectedCandidates"
So, I have to first find content place holder, then, tabcontainer, then, tabpanel, then, control and then gridview.

Wednesday, January 27, 2010

For using excel file as database

6:11 AM Posted by Unknown , No comments
For reading Excel files and getting the data
string FilePath = Server.MapPath("exmaple.xls");

DataSet myDataset = new DataSet();
string strConn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + FilePath + @";Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1""";
OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
DataTable DTable = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
//here the code will read sheet from spreadsheet with any name --generic
OleDbDataAdapter myData = new OleDbDataAdapter
(@"SELECT * FROM [" +
DTable.Rows[0]["TABLE_NAME"].ToString() + "]", conn);
//
myData.Fill(myDataset);

Tuesday, January 26, 2010

Firebug Extensions

9:45 PM Posted by Unknown , No comments
Firebug is the most usefult addon tool for web development. It can help us to find the issues in css, ajax requests etc and many features. There are some other addons which can help to improve the utility of firebug.
Learn More

Monday, January 25, 2010

Saturday, January 23, 2010

Ajax and UpdatePanel performance improvement

7:38 PM Posted by Unknown , , , , No comments
Most of the newbie programmers like me are ajaxifying a site by putting updatepanels all over the site. Now, I came to know that, putting updatepanel will not help you to improve your site's speed. We are using it, since it is very easy. You can understand why ajax updatenpanels should be avoided from the following link

Why UpdatePanel Dangerous



If you still want to use updatepanel, check the following link to speed up the updatepanel performance.

Speeding up UpdatePanel



Also, you can use a dll, scriptreferenceprofiler, to find the ajax scripts used in a page and combine them, so that, only that script requests will be used in that specific page, which reduces the loading time. You can understand how to use it from the following msdn video.

Script Combining

You can download ScriptReferenceProfile from the following url
Download

Use them as follows

Add reference to the dll.
<%@ Register Assembly="ScriptReferenceProfiler" Namespace="ScriptReferenceProfiler" TagPrefix="cc1" %>

Top Money giving Paid To Click site

9:49 AM Posted by Unknown No comments
Its an off topic. I just came to know about this site. They are giving the maximum for click. 50 cents for just clicking banners and 1 USD for reading their emails. Also, referral bonus is there.

payingptr.com

Friday, January 22, 2010

Know the control which caused the postback

8:28 PM Posted by Unknown , No comments
I got this from some site. It can be used to know the control which caused the postback.

 public static Control GetPostBackControl(Page thePage)
    {
        Control myControl = null;
        string ctrlName = thePage.Request.Params.Get("__EVENTTARGET");
        if (((ctrlName != null) & (ctrlName != string.Empty)))
        {
            myControl = thePage.FindControl(ctrlName);
        }
        else
        {
            foreach (string Item in thePage.Request.Form)
            {
                Control c = thePage.FindControl(Item);
                if (((c) is System.Web.UI.WebControls.Button))
                {
                    myControl = c;
                }
            }

        }
        return myControl;
    }

Display updateprogress in the clicked position

8:22 PM Posted by Unknown , No comments
On the following example, progress bar(UpdateProgress1) is displayed on the position of the button which got clicked


function pageLoad()

     {     

           var manager = Sys.WebForms.PageRequestManager.getInstance();
   
          
       manager.add_beginRequest(OnBeginRequest);
   
    }

    function OnBeginRequest(sender, args)
    {
 
          var postBackElement = args.get_postBackElement();
          var position = $("#"+postBackElement.id).offset();
         
         
          $("#<%=UpdateProgress1.ClientID%>").css({'position' : 'absolute', 'z-index' : '1002', 'overflow' : 'auto','top' : position.top,'left' : position.left}).fadeIn(100);

}

JQuery default functions

8:21 PM Posted by Unknown No comments
Following is the jquery default function that is run. we can use this to get the ajaxrequests
function pageLoad() {
            if (!Sys.WebForms.PageRequestManager.getInstance().get_isInAsyncPostBack()) {
                Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(AjaxBegin);      
                Sys.WebForms.PageRequestManager.getInstance().add_endRequest(AjaxEnd);      

            }
        }

8:16 PM Posted by Unknown No comments
Use ScriptManager.RegisterStartupScript, when using ajax updatepanel to add javascript from codebehind.
for eg. just showing a message box, on of a button in updatepanel
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "scriptname", "var position=$('#" + Btn.ClientID + "').offset();$('#').html('Button clicked').css(position).fadeIn(2000).fadeOut(2000);", true);

can get position using position method of jquery

First Post

8:14 PM Posted by Unknown No comments
My First Post. Hope this blog will help me and others too.

I am going to post all the new things I am learning everyday regarding programming. Hope it helps somebody.