Thursday 30 January 2014

AJAX - Modal Popup Extender - how to fix error _foregroundElement.parentNode' is null or not an object

Replace


<cc1:ModalPopupExtender ID="ModalPopupExtender4" runat="server"    TargetControlID="LinkButton1" PopupControlID="Panel1">
</cc1:ModalPopupExtender>
 <div id="Test" visible="false" runat="server">
 <asp:LinkButton ID="LinkButton1" runat="server">LinkButton</asp:LinkButton>
 </div>

 <asp:Panel ID="Panel1" runat="server" CssClass="modalPopup" ScrollBars="Horizontal"
                OnLoad="Panel1_Load" >
   <div class="modalWholePage">
   </div>

-- code behind
    protected void ShowMoreSearchOptions_Click(object sender, EventArgs e)
    {
        Test.Visible = true;
    }

With
<cc1:ModalPopupExtender ID="ModalPopupExtender4" runat="server" TargetControlID="LinkButton1" PopupControlID="Panel1">
</cc1:ModalPopupExtender>


 <div id="Test" visible="false" runat="server">
 <asp:LinkButton ID="LinkButton1" runat="server" Visible ="false">LinkButton</asp:LinkButton>
 </div>


 <asp:Panel ID="Panel1" runat="server" CssClass="modalPopup" ScrollBars="Horizontal"
                OnLoad="Panel1_Load" Style="display: none">
 <div class="modalWholePage">
 </div>


-- code behind
    protected void ShowMoreSearchOptions_Click(object sender, EventArgs e)
    {
        Test.Visible = true;
        LinkButton1.Visible = true;
    }

Wednesday 29 January 2014

Javascript - how to fix error - JavaScript runtime error: Object doesn't support property or method 'setAttribute'


Watch online

Replace

    <script type="text/javascript">
        function CheckTextBox() {
           var AccountNumber = document.getElementById('<%= txtSomething.ClientID %>').value;
            if (document.getElementById('<%= rbCheckYesNo.ClientID %>').checked) {
                AccountNumber.setAttribute("readonly", "false");
                AccountNumber.focus();
            }
        }
    </script>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:textbox id="txtSomething" onchange="CheckTextBox()" runat="server"></asp:textbox>
        <asp:radiobutton id="rbCheckYesNo" runat="server">
    </asp:radiobutton></div>
</form>
</body>
with

    <script type="text/javascript">
        function CheckTextBox() {
           var AccountNumber = document.getElementById('<%= txtSomething.ClientID %>');
            if (document.getElementById('<%= rbCheckYesNo.ClientID %>').checked) {
                AccountNumber.setAttribute("readonly", "false");
                AccountNumber.focus();
            }
        }
    </script>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:textbox id="txtSomething" onchange="CheckTextBox()" runat="server"></asp:textbox>
        <asp:radiobutton id="rbCheckYesNo" runat="server">
    </asp:radiobutton></div>
</form>
</body>

Sunday 12 January 2014

MVC 5 - How to pass data from controller to view using ViewBag

Watch this example on YouTube



1. create method that will receive some arguments
         public ActionResult DisplayMessage(string city, int age)
        {
            ViewBag.City = city;
            ViewBag.Age = age;
            return View();
        }
2. Add view and the following code to it
@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@{
    <p>The following city: @ViewBag.City is @ViewBag.Age years old.</p>
}

Laptop - How to change keyboard from French to English

(LEFT)Ctrl + (RIGHT)Shift

MVC 5 - How to pass parameters as route data

Watch this example on YouTube



So instead of
http://localhost:53071/Test/DisplayMessage/city=Kyiv?age=1500
I want user to access my page through this link
http://localhost:53071/Test/DisplayMessage/Kyiv/1500

In order to do so,
first create method called DisplayMessage in Test controller

     public string DisplayMessage(string city, int age)
        {
            return HttpUtility.HtmlEncode("the following city: " + city + "is " + age.ToString() + "years old");
        }

then modify RouteConfig.cs file inside App_Start folder and add the following
            routes.MapRoute(
                name: "Test",
                url: "{controller}/{action}/{city}/{age}"
               
            );

MVC 5 - How to change default startup page (Controller)

Watch this example on Youtube


You can change default controller(page) in App_Start/RouteConfig.cs








Modify controller value, change it to the controller that should be your startup page       
defaults: new { controller = "Test", action = "TestPage", id = UrlParameter.Optional }

For more details, please watch video above.



 

Tuesday 7 January 2014

C# - How to fix error The name 'DbNull' does not exist in the current context


Replace
 if (row["ID"] != DbNull.value)
  {
                    myID = (int)row["ID"];
  }

with
  if (row["ID"] != null)
  {
                    myID = (int)row["ID"];
  }


Thursday 2 January 2014

How to fix issues where e.Row.Cells returns empty string while accessing gridview rows

 Watch this example on YouTube

REPLACE

 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                string test1 = e.Row.Cells[0].Text;
            }
        }
WITH
 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Label lb = (Label)e.Row.Cells[0].FindControl("Label1");
                string test2 = lb.Text;

            }
        }