dot-nugget

Code and Knowledgebase Site

Code and Knowledgebase Site for Rumery Enterprises, LLC. Tampa Bay area custom software developer

asp.net dirty form checker in dynamic controls

clock April 20, 2012 07:07 by author

using jquery and telerik ajax manager I was able to add a dirty check to the imput controls.

1. ascx page with dynamic controls loading in a place holder.

2. Add jQuery code to add the change function.  but code on bottom of ascx page.
 
<script type="text/javascript">
     var _isDirty = false;
     $(":input").change(function () {
         setDirty();
     });

     // checks to see if form is dirty before leaving page.
     //close, update and cancel buttons will set the isDirty to 0 to avoid alert .
     $(window).bind('beforeunload', function () {
         checkSave();
     }
    );

     var isDirty;
     isDirty = 0;

     function setDirty() {
         isDirty = 1;
     }

     function checkSave() {
         var sSave;
         if (isDirty == 1) {
             sSave = window.confirm("You have some changes that have NOT been saved. Click OK to save now or CANCEL to continue without saving.");
             if (sSave == true) {
                 $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("Save");
               
             } else {
                 return true;
             }
         }
     }

    </script>

 

3 telerik ajax manager

 <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"
        onajaxrequest="RadAjaxManager1_AjaxRequest">
</telerik:RadAjaxManager>

 

4. cs code behind for ajax request

 protected void RadAjaxManager1_AjaxRequest(object sender, Telerik.Web.UI.AjaxRequestEventArgs e)
        {
            if (e.Argument == "Save")
            {
                SaveData();
            }
        }

5. page load to set some buttons to set isDirty back to 0
   protected void Page_Load(object sender, EventArgs e)
        {
        
            ibUpdate.Attributes.Add("onclick", "isDirty = 0;");
            ibCancel.Attributes.Add("onclick", "isDirty = 0;");        
        }



Microsoft JScript runtime error: Unable to get value of the property 'id': object is null or undefined

clock April 14, 2012 04:22 by author

Received this error when Telerik and the AjaxToolKit were used in the same web site.  Removing the AjaxToolKit solved the issue. 

.Net 4 web site in VS2010.



How to use linq to iterate web controls

clock February 3, 2012 04:46 by author

using link I can set properties to each type of control in a control class

using OfType<>() you can pass in a type of control, like panel, and then iterate over the collection.  The example below iterates over all Panels's in an update panel control and sets all but the one passed in to visiable = false.

private void SetDisplay(string panelName)
        {
            //List<Panel> panels = (List<Panel>)this.Controls.OfType<Panel>();
            var pnls = from control in UpdatePanel1.Controls[0].Controls.OfType<Panel>()                     
                       select control;

            foreach (Panel pn in pnls)
            {
                if (pn.ID == panelName)
                    pn.Visible = true;
                else
                    pn.Visible = false;
            }

        }



get magento invoice entity using order id c#

clock November 1, 2011 10:41 by author

Couldn't find a c# example so I created one.  A customer wanted to pull notes from an Invoice to place in SAGE when the processing orders were being pulled down via the v2 API.

//pass in the order_id value from your salesOrderEntity object.

 public salesOrderInvoiceEntity[] GetSalesOrders(string orderID)
        {
            if (string.IsNullOrEmpty(this.SessionId))
                this.Login();

            filters listFilters = null;

            complexFilter cFilter = new complexFilter();

            cFilter.key = "order_id";
            cFilter.value = new associativeEntity
            {
                key = "equal",
                value = orderID
            };

            listFilters = new filters();
            listFilters.complex_filter = new complexFilter[] { cFilter };

            salesOrderInvoiceListRequest req = new salesOrderInvoiceListRequest(this.SessionId, listFilters);
            return magentoService.salesOrderInvoiceList(req).result;
        }


//I Only need the last comment but you can return the salesOrderInvoiceCommentEntity object and parse all that the invoice has.
  public string  GetInvoiceComments(string id)
        {
            if (string.IsNullOrEmpty(this.SessionId))
                this.Login();
            salesOrderInvoiceInfoResponse req = magentoService.salesOrderInvoiceInfo(new salesOrderInvoiceInfoRequest(this.SessionId, id));
            if (req.result.comments != null)
                return req.result.comments[0].comment;
            else
                return string.Empty;

        }

 

 

 



tsql find fragmented indexes and rebuild sql server 2005

clock September 27, 2011 15:34 by author

this will loop thru all tables that have a frag% > 40 and also puts the schema in front of the table name.

create table #frag(
tabName varchar(200)
)
insert into #frag
select S.name + ‘.’ + tbl.[name] TableName
from sys.dm_db_index_physical_stats (null, null, null, null, null )as mn
inner join sys.tables tbl on tbl.[object_id] = mn.[object_id]
inner join sys.indexes ind on ind.[object_id] = mn.[object_id]
inner join sys.schemas S on tbl.schema_id = S.schema_id
where [database_id] = db_id() and mn.avg_fragmentation_in_percent > 40
order by mn.avg_fragmentation_in_percent desc

while exists(select top 1 tabName from #frag)
begin
declare @name as varchar(200), @sql varchar(1000)
select top 1 @name = tabName from #frag
set @sql = ‘ALTER INDEX ALL ON ‘ + @name + ‘ REBUILD’
select @sql
delete from #frag where tabName = @name
exec(@sql)
end

drop table #frag



tsql Update or Insert in one stored procedure

clock June 4, 2011 08:35 by author

try update first and if rowcount = 0 then you need to insert.

SET NOCOUNT OFF;
set XACT_ABORT ON;
-- LEAVE NOCOUNT OFF IF SET TO ON THEN THE ROWCOUNT CHECK WILL FAIL.

 

 update [dbo].[mem_Favorites]
  set isActive = @isActive
  where mem_id = @mem_id and mem_favorite_id = @mem_favorite_id
  
-- if rowcount is  0 then it must be an insert

 

if @@ROWCOUNT = 0
 begin
  INSERT INTO [dbo].[mem_Favorites]
      ([mem_id]
      ,[mem_favorite_id]
      ,[DateAdded]
      ,[isActive])
   VALUES
      (@mem_id
      ,@mem_favorite_id
      ,GETDATE()
      ,@isActive)
 end
 



Get TimeZone List for .Net 2 C#

clock February 24, 2011 05:23 by author

This list is for .net version 3 and lower.  3.5 and 4 have a timeZoneInfo class that can provide this list. 

set your dropdown list to call the method on onLoad

 protected void DropDownListTimeZones_Load(object sender, EventArgs e)
 {
  if(!Page.IsPostBack)
  {
   DropDownList list = (DropDownList)sender;
          list.Items.Add(new ListItem("(UTC-12:00) International Date Line West", "Dateline Standard Time"));
list.Items.Add(new ListItem("(UTC-11:00) Coordinated Universal Time-11", "UTC-11"));
list.Items.Add(new ListItem("(UTC-11:00) Samoa", "Samoa Standard Time"));
list.Items.Add(new ListItem("(UTC-10:00) Hawaii", "Hawaiian Standard Time"));
list.Items.Add(new ListItem("(UTC-09:00) Alaska", "Alaskan Standard Time"));
list.Items.Add(new ListItem("(UTC-08:00) Baja California", "Pacific Standard Time (Mexico)"));
list.Items.Add(new ListItem("(UTC-08:00) Pacific Time (US & Canada)", "Pacific Standard Time"));
list.Items.Add(new ListItem("(UTC-07:00) Arizona", "US Mountain Standard Time"));
list.Items.Add(new ListItem("(UTC-07:00) Chihuahua, La Paz, Mazatlan", "Mountain Standard Time (Mexico)"));
list.Items.Add(new ListItem("(UTC-07:00) Mountain Time (US & Canada)", "Mountain Standard Time"));
list.Items.Add(new ListItem("(UTC-06:00) Central America", "Central America Standard Time"));
list.Items.Add(new ListItem("(UTC-06:00) Central Time (US & Canada)", "Central Standard Time"));
list.Items.Add(new ListItem("(UTC-06:00) Guadalajara, Mexico City, Monterrey", "Central Standard Time (Mexico)"));
list.Items.Add(new ListItem("(UTC-06:00) Saskatchewan", "Canada Central Standard Time"));
list.Items.Add(new ListItem("(UTC-05:00) Bogota, Lima, Quito", "SA Pacific Standard Time"));
list.Items.Add(new ListItem("(UTC-05:00) Eastern Time (US & Canada)", "Eastern Standard Time"));
list.Items.Add(new ListItem("(UTC-05:00) Indiana (East)", "US Eastern Standard Time"));
list.Items.Add(new ListItem("(UTC-04:30) Caracas", "Venezuela Standard Time"));
list.Items.Add(new ListItem("(UTC-04:00) Asuncion", "Paraguay Standard Time"));
list.Items.Add(new ListItem("(UTC-04:00) Atlantic Time (Canada)", "Atlantic Standard Time"));
list.Items.Add(new ListItem("(UTC-04:00) Cuiaba", "Central Brazilian Standard Time"));
list.Items.Add(new ListItem("(UTC-04:00) Georgetown, La Paz, Manaus, San Juan", "SA Western Standard Time"));
list.Items.Add(new ListItem("(UTC-04:00) Santiago", "Pacific SA Standard Time"));
list.Items.Add(new ListItem("(UTC-03:30) Newfoundland", "Newfoundland Standard Time"));
list.Items.Add(new ListItem("(UTC-03:00) Brasilia", "E. South America Standard Time"));
list.Items.Add(new ListItem("(UTC-03:00) Buenos Aires", "Argentina Standard Time"));
list.Items.Add(new ListItem("(UTC-03:00) Cayenne, Fortaleza", "SA Eastern Standard Time"));
list.Items.Add(new ListItem("(UTC-03:00) Greenland", "Greenland Standard Time"));
list.Items.Add(new ListItem("(UTC-03:00) Montevideo", "Montevideo Standard Time"));
list.Items.Add(new ListItem("(UTC-02:00) Coordinated Universal Time-02", "UTC-02"));
list.Items.Add(new ListItem("(UTC-02:00) Mid-Atlantic", "Mid-Atlantic Standard Time"));
list.Items.Add(new ListItem("(UTC-01:00) Azores", "Azores Standard Time"));
list.Items.Add(new ListItem("(UTC-01:00) Cape Verde Is.", "Cape Verde Standard Time"));
list.Items.Add(new ListItem("(UTC) Casablanca", "Morocco Standard Time"));
list.Items.Add(new ListItem("(UTC) Coordinated Universal Time", "Coordinated Universal Time"));
list.Items.Add(new ListItem("(UTC) Dublin, Edinburgh, Lisbon, London", "GMT Standard Time"));
list.Items.Add(new ListItem("(UTC) Monrovia, Reykjavik", "Greenwich Standard Time"));
list.Items.Add(new ListItem("(UTC+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna", "W. Europe Standard Time"));
list.Items.Add(new ListItem("(UTC+01:00) Belgrade, Bratislava, Budapest, Ljubljana, Prague", "Central Europe Standard Time"));
list.Items.Add(new ListItem("(UTC+01:00) Brussels, Copenhagen, Madrid, Paris", "Romance Standard Time"));
list.Items.Add(new ListItem("(UTC+01:00) Sarajevo, Skopje, Warsaw, Zagreb", "Central European Standard Time"));
list.Items.Add(new ListItem("(UTC+01:00) West Central Africa", "W. Central Africa Standard Time"));
list.Items.Add(new ListItem("(UTC+01:00) Windhoek", "Namibia Standard Time"));
list.Items.Add(new ListItem("(UTC+02:00) Amman", "Jordan Standard Time"));
list.Items.Add(new ListItem("(UTC+02:00) Athens, Bucharest, Istanbul", "GTB Standard Time"));
list.Items.Add(new ListItem("(UTC+02:00) Beirut", "Middle East Standard Time"));
list.Items.Add(new ListItem("(UTC+02:00) Cairo", "Egypt Standard Time"));
list.Items.Add(new ListItem("(UTC+02:00) Damascus", "Syria Standard Time"));
list.Items.Add(new ListItem("(UTC+02:00) Harare, Pretoria", "South Africa Standard Time"));
list.Items.Add(new ListItem("(UTC+02:00) Helsinki, Kyiv, Riga, Sofia, Tallinn, Vilnius", "FLE Standard Time"));
list.Items.Add(new ListItem("(UTC+02:00) Jerusalem", "Jerusalem Standard Time"));
list.Items.Add(new ListItem("(UTC+02:00) Minsk", "E. Europe Standard Time"));
list.Items.Add(new ListItem("(UTC+03:00) Baghdad", "Arabic Standard Time"));
list.Items.Add(new ListItem("(UTC+03:00) Kuwait, Riyadh", "Arab Standard Time"));
list.Items.Add(new ListItem("(UTC+03:00) Moscow, St. Petersburg, Volgograd", "Russian Standard Time"));
list.Items.Add(new ListItem("(UTC+03:00) Nairobi", "E. Africa Standard Time"));
list.Items.Add(new ListItem("(UTC+03:30) Tehran", "Iran Standard Time"));
list.Items.Add(new ListItem("(UTC+04:00) Abu Dhabi, Muscat", "Arabian Standard Time"));
list.Items.Add(new ListItem("(UTC+04:00) Baku", "Azerbaijan Standard Time"));
list.Items.Add(new ListItem("(UTC+04:00) Port Louis", "Mauritius Standard Time"));
list.Items.Add(new ListItem("(UTC+04:00) Tbilisi", "Georgian Standard Time"));
list.Items.Add(new ListItem("(UTC+04:00) Yerevan", "Caucasus Standard Time"));
list.Items.Add(new ListItem("(UTC+04:30) Kabul", "Afghanistan Standard Time"));
list.Items.Add(new ListItem("(UTC+05:00) Ekaterinburg", "Ekaterinburg Standard Time"));
list.Items.Add(new ListItem("(UTC+05:00) Islamabad, Karachi", "Pakistan Standard Time"));
list.Items.Add(new ListItem("(UTC+05:00) Tashkent", "West Asia Standard Time"));
list.Items.Add(new ListItem("(UTC+05:30) Chennai, Kolkata, Mumbai, New Delhi", "India Standard Time"));
list.Items.Add(new ListItem("(UTC+05:30) Sri Jayawardenepura", "Sri Lanka Standard Time"));
list.Items.Add(new ListItem("(UTC+05:45) Kathmandu", "Nepal Standard Time"));
list.Items.Add(new ListItem("(UTC+06:00) Astana", "Central Asia Standard Time"));
list.Items.Add(new ListItem("(UTC+06:00) Dhaka", "Bangladesh Standard Time"));
list.Items.Add(new ListItem("(UTC+06:00) Novosibirsk", "N. Central Asia Standard Time"));
list.Items.Add(new ListItem("(UTC+06:30) Yangon (Rangoon)", "Myanmar Standard Time"));
list.Items.Add(new ListItem("(UTC+07:00) Bangkok, Hanoi, Jakarta", "SE Asia Standard Time"));
list.Items.Add(new ListItem("(UTC+07:00) Krasnoyarsk", "North Asia Standard Time"));
list.Items.Add(new ListItem("(UTC+08:00) Beijing, Chongqing, Hong Kong, Urumqi", "China Standard Time"));
list.Items.Add(new ListItem("(UTC+08:00) Irkutsk", "North Asia East Standard Time"));
list.Items.Add(new ListItem("(UTC+08:00) Kuala Lumpur, Singapore", "Malay Peninsula Standard Time"));
list.Items.Add(new ListItem("(UTC+08:00) Perth", "W. Australia Standard Time"));
list.Items.Add(new ListItem("(UTC+08:00) Taipei", "Taipei Standard Time"));
list.Items.Add(new ListItem("(UTC+08:00) Ulaanbaatar", "Ulaanbaatar Standard Time"));
list.Items.Add(new ListItem("(UTC+09:00) Osaka, Sapporo, Tokyo", "Tokyo Standard Time"));
list.Items.Add(new ListItem("(UTC+09:00) Seoul", "Korea Standard Time"));
list.Items.Add(new ListItem("(UTC+09:00) Yakutsk", "Yakutsk Standard Time"));
list.Items.Add(new ListItem("(UTC+09:30) Adelaide", "Cen. Australia Standard Time"));
list.Items.Add(new ListItem("(UTC+09:30) Darwin", "AUS Central Standard Time"));
list.Items.Add(new ListItem("(UTC+10:00) Brisbane", "E. Australia Standard Time"));
list.Items.Add(new ListItem("(UTC+10:00) Canberra, Melbourne, Sydney", "AUS Eastern Standard Time"));
list.Items.Add(new ListItem("(UTC+10:00) Guam, Port Moresby", "West Pacific Standard Time"));
list.Items.Add(new ListItem("(UTC+10:00) Hobart", "Tasmania Standard Time"));
list.Items.Add(new ListItem("(UTC+10:00) Vladivostok", "Vladivostok Standard Time"));
list.Items.Add(new ListItem("(UTC+11:00) Magadan", "Magadan Standard Time"));
list.Items.Add(new ListItem("(UTC+11:00) Solomon Is., New Caledonia", "Central Pacific Standard Time"));
list.Items.Add(new ListItem("(UTC+12:00) Auckland, Wellington", "New Zealand Standard Time"));
list.Items.Add(new ListItem("(UTC+12:00) Coordinated Universal Time+12", "UTC+12"));
list.Items.Add(new ListItem("(UTC+12:00) Fiji", "Fiji Standard Time"));
list.Items.Add(new ListItem("(UTC+12:00) Petropavlovsk-Kamchatsky - Old", "Kamchatka Standard Time"));
list.Items.Add(new ListItem("(UTC+13:00) Nuku'alofa", "Tonga Standard Time"));

 

   ListItem item = list.Items.FindByValue("Eastern Standard Time");
   if(item != null)
    item.Selected = true;
   
   LoadTimeZone();
          
  }  
 }



AjaxToolkit combox example using webservice

clock January 13, 2011 16:47 by author

uses 4.0 .Net Framework and AjaxToolkit v4

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>

 <ajaxToolkit:ComboBox ID="cbProducts" runat="server" DropDownStyle="DropDownList"
                                    AutoCompleteMode="Suggest" RenderMode="Block"  AutoPostBack="true" OnSelectedIndexChanged="ComboBox1_SelectedIndexChanged"
                                    AppendDataBoundItems="false" CssClass="AquaStyle">
                                </ajaxToolkit:ComboBox>

code behind example

private void FormatPage() {

 WebServiceSoapClient wsc = new WebServiceSoapClient ();

cbProducts.DataTextField = "itemNo";

cbProducts.DataValueField = "itemNo";

cbProducts.DataSource = wscc.GetProducts(); //dataset could use generic or other bindable object

cbProducts.DataBind();

cbProducts.Items.Add("--Select Item --");  //add item to top of list

 cbProducts.SelectedValue = ""; 

}

link to more examples here



vb.net hastable example

clock October 4, 2010 13:13 by author


        Dim hsh As New System.Collections.Hashtable
        Dim blnCreated As Boolean = False

        hsh.Add("@fname", txtFName.Text.Trim())
        hsh.Add("@lname", txtLName.Text.Trim())
        hsh.Add("@email", txtEmail.Text.Trim())
        hsh.Add("@company", txtCompany.Text.Trim())
        hsh.Add("@password", txtPassword.Text.Trim())
        hsh.Add("@refer", functions.GetCookie("refer"))
        hsh.Add("@entry", functions.GetCookie("entry"))
        hsh.Add("@phone", txtPhone.Text)
        hsh.Add("@countyid", county_id.SelectedValue)
You can pass the hastable to an email function or database crud method and loop thru each item.

Nice when you have an application that adds records to a db or smtp send mail function.



how do I setup smtp.gmail.com in asp.net?

clock September 29, 2010 12:14 by author

The code below will allow you to send email to smtp.gmail.com .  this works when you setup your domail to be hosted by google or if you have a Gmail account.

using System.Net.Mail;
using System.Net;

try

{
 

SmtpClient smtpClient = new SmtpClient("smtp.gmail.com",587);
smtpClient.EnableSsl = true;
smtpClient.DeliveryMethod =  SmtpDeliveryMethod.Network;
smtpClient.Credentials =  new NetworkCredential("username@yourdomain.com", "password");
 

MailMessage message = new MailMessage(from, to, subject, body);

smtpClient.Send(message);
}
catch (Exception ex)
{
throw ex;

}



Sign in