Monday, December 3, 2012

Bind DropDownList from javascript

Generally DropDownList also we can bind from clientside. The step by step procedure i have mentioned here.

 we have to get the data from the database and need to bind to dropdown means we need to get it on "ListView" is the better way. I have used PageMethods to get the data to clientside.

Javascript:
<script type="text/javascript">

        function pageLoad() {
            PageMethods.GetData(CallMethod);
        }

        function CallMethod(result) {
            var ddl = document.getElementById("ddl");
            for (D = 0; D < result.length; D++) {
                opt = new Option(result[D], result[D]);
                ddl.add(opt);
            }
        }

</script>

Here the pageLoad method works just like server side pageload event. In this pageload i have got data and binded to dropdownlist. In CallMethod function "result" indicates the obtained data which we need to bind to dropdown in the form of list.

PageMethods:

[WebMethod(EnableSession=true)]
    public static List<string> GetData()
    {
        List<string> list = new List<string>();
        list.Add("one");
        list.Add("two");
        list.Add("three");
        list.Add("four");
        list.Add("five");
        return list;
    }

By this pageMethod list<string> is returning to javascript function.

You can get the sample code by the attached document.....

Difference between .ToString and “as string” in C#

There is a simple but important difference between these three…
ToString() raise exception when the object is null
So in the case of object.ToString(), if object is null, it raise NullReferenceException.
Convert.ToString() return string.Empty in case of null object
(string) cast assign the object in case of null
So in case of
MyObject o = (string)NullObject;
But when you use o to access any property, it will raise NullReferenceException.

Monday, October 29, 2012

Toggle Display (On / Off)

JavaScript
<script language="javascript" type="text/javascript">

  function TDisplay(elementID) {

  var CurrentElement = document.getElementById(elementID);

  CurrentElement.style.display = (CurrentElement.style.display != 'none') ? 'none' : '';

  return false;

}

</script>

.ASPX Page
<asp:LinkButton ID="LinkButton1" runat="server" OnClientClick="return TDisplay('panel1');">

Toggle Display(On / Off)</asp:LinkButton>

<asp:Panel ID="panel1" runat="server">

    Panel content here!

</asp:Panel>

Pass data from one page to another new popup window

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title></title>

<script language="javascript" type="text/javascript">

    function PassData() {

        var Qstr = document.getElementById("<%=txtData.ClientID %>").value;

        window.open('Your-Target-Page.aspx?ID=' + Qstr, 'NewWindow', 'width=400,height=300,location=no,menubar=no,resizable=no,scrollbars=no,status=yes,toolbars=no');

        return  false;

}



</script>

</head>

<body>

    <form id="form1" runat="server">

    <div>

<asp:TextBox ID="txtData" runat="server" Text="23"

CssClass="TextBox"></asp:TextBox>

<asp:Button ID="btnRedirect" runat="server" Text="Window Open"

CssClass="Button" OnClientClick="return PassData(); " />

    </div>

    </form>

</body>

Monday, October 15, 2012

Hide Files or Folders Using Command Prompt

For that you need to follow the following instructions

  1. Press windowkey+R: Run command dialog box appears.
  2. Now type "cmd" and hit enter. A command prompt window displays.
  3. Now type "attrib +s +h E:\collegephotos" and hit enter.
  4. The folder "collegephotos" will be hidden (Note: It cannot be viewed by any search options)

    (To view this folder again, use the same command but replace '+' with '-' on both flags 's' and 'h')