Wednesday 9 November 2011

Beware of recursion on getter/setter methods

Question Received:
      The Application is not responding apparently.

Solution:
     Check the code for any defects like recursion in the statement and methods.
     Defect I have found from the getter/setter methods.
     private string _mail;
     public string Mail
     {
          get
          {
               return _mail;
          }
          set
          {
              if(condition)
              {
                   Mail="mail@daemon.com";
              }
          }
     }
     public DataSource()
     {
          Mail="mail@daemon.com";
     }

[Note:]
The culprit is,
       In setter method, Mail="mail@daemon.com" makes it call the setter method recursively.

How to add the extender to Silverlight TextBox

Question Received:
         To add the extender to validate any value typed in the TextBox.

Solution:
        i. Create DataSource.cs which contains the getter/setter methods for evaluating the value in the TextBox.
        ii.Integrate it with the Page.xaml.cs using instance to point the DataContext in the LayoutRoot.
        iii.Bind the Data to the necessary controls (ie.,TextBox).
        iv.Throw the error on exception and make it to be caught from 'LayoutRoot'.
        v. Add the necessary handler in the 'page.xaml.cs'.
        vi.However, all the handlers will be coded in the 'page.xaml.cs'.
        vii.Alright, Compile and execute it will be working.
        viii.Download the detailed document from, ExtenderToSilverLightControls.docx.
        ix.Download the source from, SilverlightDataValidation.

[Note:]
    --> Make sure that the DataSource to initialize the value, that will not throw the error on Page_init() or page_Load().
    --> If so, silverlight application will not be starting.

Deploying the Web Application or Web Service in IIS.

Question Received:
       How to publish the Web Components into the IIS Server 7.0
from 'MicrosoftVisualStudio2010'.

Solution:
      i. Build the Entire Project and solution.
      ii.Right-Click on the project, select 'Build Deployment Package'.
      iii.Right-Click on the project, select 'Publish'.
      iv.Select 'FileSystem' to deploy.
      v. Browse for Target Location.
      vi. Click 'OK' to publish.
      vii.Go to target location and copy the path.
      viii.Start IIS Manager 7.0 ('inetmgr.exe')
      ix.Right-Click 'DefaultWebSite'-->Add Application.
      x. Give the Application Name and TargetPath.
      xi.Browse the Application from InternetExplorer
      
    That's it. Finished.
[Note:] Best Practices,
              --> Choose 'Delete the files in the targetFolder prior to publish'.
              --> Conform building the project and solution prior to publish.

Adding the 'YesNo' MessageBox in the ASP.NetWebApplication

Questions Received:
       How to add the 'YesNo' MessageBox in the ASP.Net WebApplication.

Solution:
       In the 'default.aspx.cs' page,
        private void callMessageBox()
        {
            uscMessageBox.AddMessage("Are you sure that you want update the database?", 
[NameSpace].MessageBox.enmMessageType.Attention, true, true, string.Empty);
        }

        public void MessageAnswered(object sender, [NameSpace].MessageBox.MsgBoxEventArgs e)
        {
            if (e.Answer == [NameSpace].MessageBox.enmAnswer.OK)
            {
            }
            else
            {
            }
        }
      
        In the 'page_load()' method,
             Add, uscMessageBox.MsgBoxAnswered += MessageAnswered; //Event HandlerCaller
       
[Note:] The UpdatePanel will be rendered after the method ends. Parent page control will be lost.
           when the UpdatePanel is displayed.

Tuesday 8 November 2011

How to add the MessageBox in the ASP.Net WebApplication

Question Received:
       How to add the popup messageBox in the ASP.Net Web Page.

Solution:
       First, Add a new panel over the current page. Panel should hold the
messageBox. It will be refreshed or updated whenever it renders the
messageBox.
       In the 'default.aspx' page, Register the Control Page by,
       <%@ Register 
                      Src="~/MessageBox.ascx" 
                      TagName="uscMsgBox" 
                      TagPrefix="usc" %>
       <asp:Content 
                      ID="BodyContent" 
                      runat="server" 
                      ContentPlaceHolderID="MainContent">
             <usc:uscMsgBox 
                            ID="uscMessageBox" 
                            runat="server" />
       </asp:Content>
       In the 'default.aspx.cs' page, Use the methods like,
        --> uscMessageBox.AddMessage(message [NameSpace].MessageBox.enmMessageType.Error);
        --> uscMessageBox.AddMessage(message [NameSpace].MessageBox.enmMessageType.Info);
       Add the App_Themes with default.css, icons.

       Now compile, It will work.
If Need, You can give the handler to 'OK' Button.
       i. First, write control code in the 'MessageBox.ascx.cs' page.
               protected void btnOK_Click(object sender, EventArgs e)
               {
                  if (ClickedOK != null)
                  {
                      ClickedOK(this, new MsgBoxEventArgs(enmAnswer.OK, Args));
                      Args = "";
                  }
               }
       ii. Add the Handler Event to the 'default.aspx.cs' page.
               uscMessageBox.ClickedOK += OKClick;
       iii. Write handler in the 'default.aspx.cs' page.
               public void OKClick(object sender, [NameSpace].MessageBox.
MsgBoxEventArgs e)
               {
                   if (confirmContinue)
                   {
                        confirmContinue = false;
                        Response.Redirect("default.aspx");               
                   }
               }
        iv. Please make changes in the 'Message.ascx.cs' page.
            OnPreRender()
                //ModalPopUpExtender_OKButton
                     mpeMsg.OkControlID = "btnD2";


  Download source from, YaBu.MessageBox.zip
[Note:] Do above four steps if You want any handler to 'OK' Button.

How to break the connection string into elements

Question Received:
        How to split the connection string into individual elements
like InitialCatalog, DBName, UserName, Passwd..

Solution:
       To break the conn. String, use the SQLConnectionBuilder as,
        SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder("");
        builder="AnyConnectionString";
        String DBName = builder.IntialCatalog.ToString();

Extender to any control in the WebApplication

Question Received:
       To add an extender to any control in the web page.

Solution:
       Add it like,
        <asp:RegularExpressionValidator
                                        ID="RegExValidatorCommonGroup"
                                        runat="server"
                                        ControlToValidate="anyTxtBox"
                                        ErrorMessage="Requires valid Text"
                                        ValidationExpression="(Expression_)+[1234]$" 
                                        ValidationGroup="CommonGroup">
       </asp:RegularExpressionValidator>
       <asp:TextBox
                       ID="anyTxtBox"
                       runat="server"
                       Width="250px"
                       ValidationGroup="CommonGroup">
      </asp:TextBox>
     <asp:Button
                   ID="AnyBtn"
                   runat="server"
                   Text="OK"
                   onclick="AnyBtn_Click"
                   ValidationGroup="CommonGroup">  
    </asp:Button>

All Controls in the same group will be triggered for validation.
[Note:] Please do care about the ValidationGroup. Else, All controls in the
page will be triggered for validation.