Monday, 18 March 2013

Cross Browser Support for inline-block Styling

Just I have a great thanks for the next two articles, they illuminate the way of bug free CSS across browsers.

Issac Schlueter
satzansatz.de



Sunday, 24 February 2013

How to set asp:CreateUserWizardas's CreateUserButton as default button of asp:Panel?



The Problem: Is to set CreateUserButton of <asp:CreateUserWizardas> as a DefaultButton of a <asp:Panel>. What to write in place of question marks of the next script? 

    <asp:Panel runat="server" ID="WizardPanel" DefaultButton="???????????????!!!!!!!!!!?">
<asp:CreateUserWizard ID="RegisterUser" runat="server" Width="449px" .......
.........................

<input type="submit" name="ctl00$ContentForm$RegisterUser$__CustomNav0$StepNextButtonButton" value="موافق" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ctl00$ContentForm$RegisterUser$__CustomNav0$StepNextButtonButton&quot;, &quot;&quot;, true, &quot;RegisterUser&quot;, &quot;&quot;, false, false))" id="ctl00_ContentForm_RegisterUser___CustomNav0_StepNextButtonButton" class="myButton" />

</asp:CreateUserWizard>
    </asp:Panel>

[*]--------------------------------------------------------------------------------------------------
The following are some approaches that don't succeed: ... but number 4 is succeeded.
[1]--------------------------------------------------------------------------------------------------
Panel1.DefaultButton = ((Button)RegisterUserStep1.CustomNavigationTemplateContainer.FindControl("StepNextButton")).ID;
Description: 
Try to set DefaultButton programatically, but FindControl() returns nothing.
[2]--------------------------------------------------------------------------------------------------
    LookForDefaultButton(this.RegisterUser.Controls);
    protected bool LookForDefaultButton(ControlCollection collection)
    {
        foreach (Control ctrl in collection)
        {
            if (ctrl.GetType() == typeof(Button) && (ctrl as Button).ID == "StepNextButton1")
            {
                this.WizardPanel.DefaultButton = ctrl.UniqueID;
                return true;
            }
            else
                if (LookForDefaultButton(ctrl.Controls))
                    return true;

        }
        return false;
    }
Description: 
Try to set DefaultButton programatically, but <asp:Panel> issued exception of IButtonControl required.
[3]--------------------------------------------------------------------------------------------------
    <asp:Button ID="RegisterPanel" runat="server" style="display:none;" 
    ValidationGroup="RegisterUser" 
    CausesValidation="true"
    OnClientClick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ctl00$ContentForm$RegisterUser$__CustomNav0$StepNextButtonButton&quot;, &quot;&quot;, true, &quot;RegisterUser&quot;, &quot;&quot;, false, false)); return;"
    />
Description: 
Try to Invok "WebForm_DoPostBackWithOptions" statment through a brooker button "RegisterUser", but causes a lot of problems with validation and postback.
[4]--------------------------------------------------------------------------------------------------
<div id="ctl00_ContentForm_WizardPanel" onkeypress="javascript:return WebForm_FireDefaultButton(event, 'ctl00_ContentForm_RegisterUser___CustomNav0_StepNextButtonButton')">
Description:
Use <div> instead of <asp:Panel> to do the same job "Invoking WebForm_FireDefaultButton() at client" without a brooker button. All validation and postback done without any problem.

Sunday, 1 July 2012

C++ GUI Libraries


MFC is a C++ framework provided by Microsoft with its famous IDE "Visual Studio", I wish to find another GUI framework, with new look and feel. I googled the internet and found some ...

First, that is a list of all toolkits available as a GUI library: http://www.atai.org/guitool/

Second, those are a recommended set of them ....


I didn't use any of them till now but I plan to do.

Friday, 20 January 2012

MFC "encountered an improper argument" message

Hi there,

The story:

My MFC application "Schedule" that I work in 2 years ago faced by a very strange bug, the application is built using VC++, VS2008 on vista platform and configured to target vista platform by assigning WINVER=0x0600, _WIN32_WINNT=0x0600, _WIN32_WINDOWS=0x0410.

It runs perfectly on whatever machine running WinXP/Vista, other O.S.s are not available to test on. An overseas customer claimed a bug when she tried to save documents, her machine was HP-dv6000 with WinXP installed. I tolled her to upgrade the machine up to WinXP-SP3, but she upgraded up to Windows7 and the bug still exist.

The Bug is such a message says "encountered an improper argument", it emerged when she tried to save/open a file.

I googled every where but nobody has solution or a resolution, even in 2009 Microsoft tolled somebody that this issue is solved in VS2010, others talk about resource conflictions according to windows upgrades.

After long time I decided to investigate, where I spent 12 hours of digging into MFC source code and files, and then discovered the problem.

It was the following statement that throws exception because of an invalided resource ID.

ENSURE(title.LoadString(nIDSTitle = bReplace ? AFX_IDS_SAVEFILE : AFX_IDS_SAVEFILECOPY));

"title" is a CString object that has to displayed in title bar of CFileDialog, it then be loaded first from a string resource AFX_IDS_SAVEFILE or AFX_IDS_SAVEFILECOPY which are not exist at the machine of the customer.

I successfully simulated the same bug on my own machine using the following lines of code.

CString temp;

ENSURE(temp.LoadString(0xF012));// 0xF012 is invalide

What is ENSURE()?

#define ENSURE(cond) ENSURE_THROW(cond, ::AfxThrowInvalidArgException() )

The following paragraph describes what is the macro ENSURE, I cut this paragraph from MSN and past it here.

The purpose of these macros is to improve the validation of parameters. The macros prevent further processing of incorrect parameters in your code. Unlike the ASSERT macros, the ENSURE macros throw an exception in addition to generating an assertion.

The macros behave in two ways, according to the project configuration. The macros call ASSERT and then throw an exception if the assertion fails. Thus, in Debug configurations (that is, where _DEBUG is defined) the macros produce an assertion and exception while in Release configurations, the macros produce only the exception (ASSERT does not evaluate the expression in Release configurations).

The macro ENSURE_ARG acts like the ENSURE macro.

To solve this bug I made two steps, First: I replaced CWinAPP::OnFileOpen using the following code:

//---------------------------------------------------------------------

void CScheduleApp::OnMyFileOpen()

{

//manual open using CFileDialog

CString strDocFileName = _T("");

CFileDialog *pDlg;

pDlg = new CFileDialog (TRUE,_T("yps"),strDocFileName,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,

_T("File (*.yps)|*.yps|All Files (*.*)|*.*||"),NULL);

//

m_strCurFolder = m_strCurFolder.IsEmpty() ? GetParentFolder():m_strCurFolder;

pDlg->m_ofn.lpstrInitialDir = m_strCurFolder.GetBuffer(MAX_PATH);

pDlg->m_ofn.lpstrTitle = _T("فتح");

if(pDlg->DoModal()==IDOK)

{

strDocFileName = pDlg->GetPathName();

//the next line is optained from the following mfc source file

//C:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\src\mfc\docmgr.cpp

AfxGetApp()->OpenDocumentFile(strDocFileName);

}

m_strCurFolder.ReleaseBuffer();

delete pDlg;

//Keep track of obtained folder as default for next open operation

m_strCurFolder = strDocFileName.IsEmpty() ? m_strCurFolder:

(strDocFileName.IsEmpty() ? _T(""):strDocFileName.Left(strDocFileName.ReverseFind('\\')+1));

//AfxMessageBox(m_strCurFolder);

theApp.WriteString(_T("CurUserFolder"),m_strCurFolder);

}

//---------------------------------------------------------------------

Second: I override CDocumment::DoSave() funtion to prevent it from calling AfxGetApp()->DoPromptFileName that uses the buggy resource, here is the code:

//---------------------------------------------------------------------

BOOL CScheduleDoc::DoSave(LPCTSTR lpszPathName, BOOL bReplace)

{

CString newName = lpszPathName;

if (newName.IsEmpty())

{

CDocTemplate* pTemplate = GetDocTemplate();

ASSERT(pTemplate != NULL);

newName = m_strPathName;

if (bReplace && newName.IsEmpty())

{

newName = m_strTitle;

// check for dubious filename

int iBad = newName.FindOneOf(_T(":/\\"));

if (iBad != -1)

newName.ReleaseBuffer(iBad);

// append the default suffix if there is one

CString strExt;

if (pTemplate->GetDocString(strExt, CDocTemplate::filterExt) &&

!strExt.IsEmpty())

{

ASSERT(strExt[0] == '.');

int iStart = 0;

newName += strExt.Tokenize(_T(";"), iStart);

}

}

//Replace the bug lines with a new technique

//if (!AfxGetApp()->DoPromptFileName(newName,

// bReplace ? AFX_IDS_SAVEFILE : AFX_IDS_SAVEFILECOPY,

// OFN_HIDEREADONLY | OFN_PATHMUSTEXIST, FALSE, pTemplate))

// return FALSE; // don't even attempt to save

if(!MyDoPromptFileName(newName,bReplace))

return false;

}

CWaitCursor wait;

if (!OnSaveDocument(newName))

{

if (lpszPathName == NULL)

{

// be sure to delete the file

TRY

{

CFile::Remove(newName);

}

CATCH_ALL(e)

{

//the normal place for the following Macro is in mfc\stdafx.h

//I bring it here becuase it is used only here and I have no plan to use it anywhere

#define DELETE_EXCEPTION(e) do { if(e) { e->Delete(); } } while (0)

//

TRACE(traceAppMsg, 0, "Warning: failed to delete file after failed SaveAs.\n");

DELETE_EXCEPTION(e);

}

END_CATCH_ALL

}

return FALSE;

}

// reset the title and change the document name

if (bReplace)

SetPathName(newName);

return TRUE; // success

}

BOOL CScheduleDoc::MyDoPromptFileName(CString& fileName, bool bReplace)

{

CFileDialog *pDlg;

pDlg = new CFileDialog (FALSE,_T("yps"),fileName,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,

_T("Timetable File (*.yps)|*.yps|All Files (*.*)|*.*||"),NULL);

CString title = bReplace ? _T("حفظ جدول الحصص"):_T("حفظ جدول الحصص في ملف آخر");

pDlg->m_ofn.lpstrTitle = title;

if(pDlg->DoModal()!=IDOK)

return FALSE;

fileName=pDlg->GetPathName();

return TRUE;

}

//---------------------------------------------------------------------

Thursday, 30 June 2011

C# access webservice from behind proxy

I was trying to use C# .NET desktop application to access a webservice from my office, the web-service is behind a proxy firewall, I was annoyed by seeing the following error message

"- The request failed with HTTP status 407: Proxy Authentication Required"

By googling I found a solution that enables me to disable proxy "http://stackoverflow.com/questions/2131933/http-407-proxy-authentication-error-when-calling-a-web-service"

To disable the proxy, in the App.config file add the following configuration

<system.net>
<defaultProxy enabled="false" useDefaultCredentials="false">
<proxy/>
<bypasslist/>
<module/>
</defaultProxy>
</system.net>

To enable the proxy and to use the default proxy settings(specified in IE) add this configuration in your App.config

<system.net>
<defaultProxy enabled="true" useDefaultCredentials="true">
<proxy/>
<bypasslist/>
<module/>
</defaultProxy>
</system.net>

Monday, 30 May 2011

Godaddy Email problem with hosted applications

My web application hosted on Godaddy can't send email messages after being uploaded there. But it works normally and can send email messages from my local machine. I tried many variations for SMTP configuration as follows but no-way for success:

1- This configuration is working from my local machine

· SMTP: smtp.mydomain.com

· Port: 25

· SSL: not enabled

· user: webmaster@mydomain.com

· password: **********

2- This configuration is not working

· SMTP: smtpout.secureserver.net

· Port: 25 or 80 or 3535 or 587

· SSL: not enabled

· Cedential user: webmaster@mydomain.com

· Cedential password: **********

3- This configuration is not working

· SMTP: smtp.secureserver.net

· Port: 25 or 80 or 3535 or 587

· SSL: not enabled

· Cedential user: webmaster@mydomain.com

· Cedential password: **********

I found the solution, and it was so old problem, since 2005, I found it in the following link:

http://forums.asp.net/t/939893.aspx/1?Problem+with+System+Net+Mail+on+GoDaddy

The problem is that SMTP-server is not smtpout.secureserver.net as Godaddy tells me. But It is relay-hosting.secureserver.net that nobody tells me at all. There is no need for user name or password, relay is open for 1000 message per day for hosted applications.

jQuery simplemodal plugin typeError: 'tagName' is null or not an object.

Many thanks for Eric's effort he made to create the great simple modal jQuery plugin.

http://www.ericmmartin.com/projects/simplemodal-demos/

I found a bug then fixed it, the bug is in $.modal.impl.create function , I think it is not new for you, where you mentioned the solution when you commented to use 'form' instead 'body' for the property appendTo.

First: the comment have to be modified to become {use '#aspnetForm'} instead of {use 'form'}
Second: in line number 344, there is still hard coding problem of the word 'body', as follows.

// add styling and attributes to the data
// append to body to get correct dimensions, then move to wrap
s.d.data = data
.attr('id', data.attr('id') || s.o.dataId)
.addClass('simplemodal-data')
.css($.extend(s.o.dataCss, {
display: 'none'
}))
.appendTo('body');


I replaced the hard coded word with s.o.appendTo object such like {.appendTo(s.o.appendTo);}, and everything goes right.