Thursday, May 15, 2014

Javascript Confirmation message on DropDownList Selected Index Changed Event


 Suppose a  user entering records in fields and before save, changed the selected DropDownList suddenly there should be a message . Otherwise the values will be lose those are loaded under   DropDownList selected index change event.I took a another textbox to hold the previous selected index value of  DropDownList .(Also we can take HiddenField)


     protected void DDlPo_SelectedIndexChanged(object sender, EventArgs e)
        {
            DDlPo.Attributes.Add("onchange", "return OnSelectedIndexChange();");
            LoadMaterialBatchDetails();//this is load method

         }





   <script language="javascript" type="text/javascript">
            function OnSelectedIndexChange() {
                  var IndexValue = document.getElementById('DDlPo');               
                  var PreviousIndexValue = document.getElementById('Txt PreviousIndexValue ').value;
                  if (IndexValue.selectedIndex != PreviousIndexValue) {
                      if (confirm("Are you sure to select another Order Number, Data will be loss for this Order Number?") == true) {
                          document.getElementById('BtnClose').click();
                          IndexValue.selectedIndex = IndexValue.selectedIndex;
                      }
                      else {
                          IndexValue.selectedIndex = PreviousIndexValue;
                      }
                }
               
            }

        </script>





Thursday, March 6, 2014

Response.Redirect () in JavaScript


Sometimes we need to redirect our page on through JavaScript function and also in code behind using JavaScript . Here the solution

   1.  Redirection Without Parameter

 var url='<%# ResolveUrl("~/Modules/WorkOrder/WorkOrderAddTask.aspx") %>';
 windows.location.href=url;;

   2.  Redirection With Parameter

 var url='<%# ResolveUrl("~/Modules/WorkOrder/WorkOrderAddTask.aspx?WID=' + Wid + '&TID='+Tid+ '") %>';

 windows.location.href=url;

  3.  Redirection from CodeBehind

  ScriptManager.RegisterStartupScript(this, this.GetType(), "scriptid", "   window.top.location='" + Page.ResolveUrl("~/FrmLogin.aspx") + "';", true);

    3.  Redirection from CodeBehind With Parameter

  ScriptManager.RegisterStartupScript(this, this.GetType(), "scriptid", "   window.top.location='" + Page.ResolveUrl("~/FrmLogin.aspx?ID="+1+"&Name="+ variable ) + "';", true); 

I hope all will work must.