Tuesday 31 December 2013

The SMTP(GMAIL) server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first.

Gmail requires you to use a secure connection. This can be set in your web.config like this:
<network host="smtp.gmail.com" enableSsl="true" ... />
and Programmatically
            SmtpClient client = new SmtpClient(server, port);
            client.EnableSsl = true;
            client.UseDefaultCredentials = false;
            // Add credentials if the SMTP server requires them.
            client.Credentials = new NetworkCredential(username, password);

Friday 29 November 2013

Passing parameter(Variable value) in ScriptManager.RegisterStartupScript.

Following Steps:

Only Alert:

string _alertValue = "Dear User: Your form" + " " + cmbFormName.SelectedValue.ToString()
                                 + " "      + "successfully";

                    ScriptManager.RegisterStartupScript(this, typeof(string), "OPEN_WINDOW", @"alert('" + _alertValue + "');window.frameElement.commitPopup();", true);



Only Redirect the Page


string ID = 25;
String test = “testabc:80”

string _alertPageRedirect = "http://" + test + "/TestForms/DisplayForm.aspx?ID=" + ID;


Page.ClientScript.RegisterStartupScript(typeof(Page), "MessagePopUp", "window.location.href = '" + _alertPageRedirect + "';", true);

 
Alert With Redirect

Page.ClientScript.RegisterStartupScript(typeof(Page), "MessagePopUp", "alert('Dear User: Please Contact Site Administrator.'); window.location.href = '"+_alertPageRedirect+"';", true);

Monday 21 October 2013

In Datatable Perform GroupBy Function(Grouped Data).

The GROUP BY statement is used in conjunction with the aggregate functions to group the result-set by one or more columns. Aggregate Function ==> CountAggregate Column ==>e.g DateGroup BY Column ==>e.g Month
 // Created GroupBy Method

DataTable GroupBy(string i_sGroupByColumn, string i_sAggregateColumn, DataTable i_dSourceTable) {

DataView dv = new DataView(i_dSourceTable);

// getting distinct values for group column

DataTable dtGroup = dv.ToTable(true, new string[] {

i_sGroupByColumn});


// adding column for the row count

dtGroup.Columns.Add(
"Count", typeof(int));

// looping thru distinct values for the group, counting

foreach (DataRow dr in dtGroup.Rows) {

dr[
"Count"] = i_dSourceTable.Compute(("Count("

+ (i_sAggregateColumn +
")")), (i_sGroupByColumn + (" = \'"
+ (dr[i_sGroupByColumn] +
"\'"))));

}

// returning grouped/counted result

return dtGroup;

}

// end GroupBy