Sunday, March 31, 2013

jQuery Modal Popups : Adding Ok, Cancel buttons

We need to add Ok, Cancel etc like any other buttons on the modal pop-up : just add them to the buttons array.


buttons: {
                    Ok: function() { alert("you pressed ok"); },
                    Cancel: function() { alert("you pressed cancel"); },
                    Close: function() { alert("Closing the dialog!"); $(this).dialog("close"); }
}

Full Code:



<head runat="server">
    <title></title>
    <script src="jquery-1.9.1.js" type="text/javascript"></script>
    <script src="jquery-1.10.2-ui.js" type="text/javascript"></script>
    <link href="jquery-1.10.2-ui.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
        $(function() {
            $("#mydlg").dialog(
            {
                buttons: {
                    Ok: function() { alert("you pressed ok"); },
                    Cancel: function() { alert("you pressed cancel"); },
                    Close: function() { alert("Closing the dialog!"); $(this).dialog("close"); }
                }
            }
            );
            $("#mybtn").click(function() {
                $("#mydlg").dialog();
            });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div id="mydlg">
    </div>
    <button type="button" id="mybtn">
    </button>
    </form>
</body>

HTML input and button

HTML input is older, but button is newer, so some old browser versions did not support button, consequently some people advise to use input rather than button.

button supports only three types : button, submit, reset
where as the older counterpart supports 10 types in html 4.01 and around 20 in html 5


For button, different browsers support different default types, where as for input the default type is text.
For IE, default type is submit.

So when you are using button without specifying type, be aware that it might be submit, and it will case a post. This might be a problem when submit behavior is not intended,e.g. you want to do something else ( calculate some value on the form itself) on a button press.

So keep in mind that <button> and <input type="button"> may not be always equivalent, but
<button type="button"> and <input type="button"> are equivalent.


If fact you should know that :
1. button type=“submit” is the same as input type=“submit”
2. button type=“reset” is the same as input type=“reset”
3. button type=“button” is the same as input type=“button”

For a very good explanation on this topic, see : http://nickcowie.com/presentation/s5-button.html

What are the types supported by the HTML input tag ?


What are the types supported by the HTML input tag ?

There are 10 such types :


text
submit
reset
passowrd
radio
button
checkbox
file
hidden
image


HTML 5 now supports additional input types :

color
date
datetime
datetime-local
email
month
number
range
search
tel
time
url
week

jQuery Learnings : sequence of including script files is important


Sequence of js :
while putting the <script> tags for jQuery js files, keep in minds the hierarchy; e.g. ui should come after jquery.

The following will not work :

    <link href="jquery-1.10.2-ui.css" rel="stylesheet" type="text/css" />
    <script src="jquery-1.10.2-ui.js" type="text/javascript"></script>
    <script src="jquery-1.9.1.js" type="text/javascript"></script>


Whereas the following will work:

    <script src="jquery-1.9.1.js" type="text/javascript"></script>
    <link href="jquery-1.10.2-ui.css" rel="stylesheet" type="text/css" />
    <script src="jquery-1.10.2-ui.js" type="text/javascript"></script>




This also negates the earlier post that we need to preserve the file names exactly. (http://rschandrastechblog.blogspot.in/2013/03/learnings-of-jquery-basic-modal-dialog.html)There might have been another error earlier.

Learnings of the jQuery Basic Modal Dialog


1. Following three files are required for correct working of jQuery Modal Dialog :
jquery-1.9.1.js
jquery-ui.css
jquery-ui.js

2. Do not rename any of the above files while downloading ( especially the last two files), because they may be refering each other by exact names and renaming them causes the app  not to work.
(Update : This may not be true, please refer to another post about jQuery modal on this date itself. http://rschandrastechblog.blogspot.in/2013/03/jquery-learnings-sequence-of-including.html)

3. A direct call to .dialog will not work, it must be wrapped in some jQuery func, at least $(function(){});

e.g the following will not work :

<head runat="server">
    <script src="jquery-1.9.1.js" type="text/javascript"></script>
    <link href="jquery-ui.css" rel="stylesheet" type="text/css" />
    <script src="jquery-ui.js" type="text/javascript"></script>
    <script type="text/javascript">
     $("#dlg").dialog();
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div id="dlg">
    </div>
    </form>
</body>

But the following will work, because $("dlg).dialog is wrapped in a jQuery function() :

Friday, March 29, 2013

Invalid postback or callback argument. Event validation is enabled using in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.

One of my new comer collegue encountered this when he was trying to add a new row to a datatable bound to a GridView and trying to put the new row in edit mode. The error was pretty confusing and bewildering for a new comer :


Invalid postback or callback argument.  Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page.  For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them.  If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.


We, the somewhat experienced people are used to such errors and ignore them as a part of our life, but the new comers are not used to it! 

The notorious error is thrown when somebody rebinds data to a GridView in Page_Load, without PostBack check. A postback check like the following solved the error  in the Page_Load: 

            if (!Page.IsPostBack){
                          GridView1.DataSource = dt;
                          GridView1.DataBind();
                          }

Thursday, March 28, 2013

How to generate from GridView ?




http://www.dotnetcurry.com/ShowArticle.aspx?ID=250
In order to prevent the Column Header to be highlighted, use the following code to generate the <thead>:
C#
if (GridView1.Rows.Count > 0)
{
GridView1.UseAccessibleHeader = true;
GridView1.HeaderRow.TableSection = TableRowSection.TableHeader;
//GridView1.FooterRow.TableSection = TableRowSection.TableFooter;
}
VB.NET
If GridView1.Rows.Count > 0 Then
GridView1.UseAccessibleHeader = True
GridView1.HeaderRow.TableSection = TableRowSection.TableHeader
'GridView1.FooterRow.TableSection = TableRowSection.TableFooter;
End If
The code above generates the <thead> tag for us instead of generating the <th> in the <tr> (which is the default html generated). I have on purpose commented out the FooterRow code, since it gives me a strange error. I have used a second approach to solve that to a certain extent. Read on.


Comparing features of LangGraph vs CrewAI

LangGraph Orchestration vs CrewAI Orchestration The following table compares LangGraph and CrewAI orchestration across their menta...