Enable Button inside RadWindow

6 posts, 0 answers
  1. Soumya
    Soumya avatar
    108 posts
    Member since:
    Jul 2012

    Posted 18 Jul 2012 Link to this post

    I have an aspx page with a button which is disabled.
    How to enable the button,only when it is poping up as a RadWindow from a parent page?
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 20 Jul 2012 Link to this post

    Hello,

    Try the following javascript to enable button on opening window.
    aspx:
    <asp:Button ID="Button1" runat="server" Text="Button" Enabled="false" />
     <telerik:RadWindow ID="RadWindow1" OnClientShow="OnClientShow" OnClientClose="OnClientClose" runat="server"></telerik:RadWindow>

    JS:
    function OnClientShow() {
           debugger;
           var btn = document.getElementById("<%= Button1.ClientID %>");
           btn.disabled = false;
       }
       function OnClientClose() {
        var btn = document.getElementById("<%= Button1.ClientID %>");
       btn.disabled = true;
       }

    Thanks,
    Shinu.
  3. Soumya
    Soumya avatar
    108 posts
    Member since:
    Jul 2012

    Posted 23 Jul 2012 Link to this post

    Hi Shinu,
    I was not able to make it work.
    I am calling radwindow from parent aspx page as below
    <telerik:RadWindowManager ID="RadWindowManager1" runat="server">
            <Windows>
          <telerik:RadWindow ID="Enqdialog" Title="Enquiry" runat="server" Height="550px" Width="1200px"
                    Left="200px" Behaviors="Close" Modal="true" />      
            </Windows>
    </telerik:RadWindowManager>

    In the aspx page(which comes as radwindow),I have the below code
    Here I am passing data from the radwindow to the parent page using the function CloseAndReload(),which is called from the code behind on button click.I need to make this button disabled
    on closing and enabled on opening radwindow.

    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
      <script type="text/javascript">
          function GetRadWindow() {
              var oWindow = null;
              if (window.radWindow) oWindow = window.radWindow; 
              else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow; 
     
              return oWindow;
          }
          function CloseAndReload() {
              var oWnd = GetRadWindow();
              oWnd.BrowserWindow.location.reload();
              oWnd.close();
          
        </script>
        </telerik:RadCodeBlock>

    <asp:Button ID="btnGetValues" Text="Register" runat="server" 
                onclick="btnGetValues_Click" >   

    aspx.cs
    protected void btnGetValues_Click(object sender, EventArgs e)
            {
                 //
                //
                if (result == false)
                {               
                    ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), Guid.NewGuid().ToString(), "CloseAndReload();", true);              
                }
       }

    I am not getting the enabled or disabled property for the button inside javascript function.I think Iam missing something.

    Thanks in advance,
    soumya
  4. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 24 Jul 2012 Link to this post

    Hi Soumya,

    If the page is not popping as a radwindow, you can disable the button on onclick event of Button2. Try the code snippets below.

    ASPX:
    <asp:Button ID="Button1"  runat="server"  />
    <asp:Button ID="Button2" CssClass="buttons" runat="server" onclick="Button2_Click"   />
    <asp:HiddenField ID="HiddenField1" runat="server" />

    CSS:
    <style type="text/css">
    .buttons
    {
     display:none;
    }
    </style>

    Javascript:
    function pageLoad()
    {
     var button2 = document.getElementById("Button2");
     var HiddenField = document.getElementById("HiddenField1");
     if ((!window.frameElement) && (HiddenField.value != "1")) // Check whether popping From RadWindow.
     {
      button2.click();
     }
    }

    C#:
    protected void Button2_Click(object sender, EventArgs e)
    {
     Button1.Enabled = false;
     HiddenField1.Value = "1";
    }

    Thanks,
    Shinu.
  5. Soumya
    Soumya avatar
    108 posts
    Member since:
    Jul 2012

    Posted 29 Jul 2012 Link to this post

    Thanks Shinu.
    It is working

    Thanks,
    Soumya
  6. Soumya
    Soumya avatar
    108 posts
    Member since:
    Jul 2012

    Posted 30 Jul 2012 Link to this post

    Hi shinu,
    One more question regarding this.
    I am trying to disable a button on the comand item of Radgrid.
    I am using the below code for disabling the button when it is not poping as radwindow .
    aspx:
    function pageLoad() {
           var button2 = document.getElementById("<%=Button2.ClientID%>");
           var HiddenField = document.getElementById("<%=HiddenField1.ClientID%>");        
           if ((!window.frameElement) && (HiddenField.value != "1")) // Check whether popping From RadWindow.
           {
               button2.click();
           }
       }
    aspx.cs:
    protected void Button2_Click(object sender, EventArgs e)
           {
               GridCommandItem commandItem1 = (GridCommandItem)gvPhoneInq.MasterTableView.GetItems(GridItemType.CommandItem)[0];
               Button btn = (Button)commandItem1.FindControl("btnRegister");
               btn.Enabled = false;
               HiddenField1.Value = "1";
           }

    On page load,the button is disabled and further on postback,it is not disabled as the Button2_Click event is not triggered due to hidden field value(hope so).
    How can I reset the value of hidden field.Setting HiddenField1.Value = string.Empty; in the page load is not working.

    Thanks,
    Soumya
Back to Top