showing message box on control's modal popup extender

ε祈祈猫儿з 提交于 2019-12-02 10:54:18

问题


I have a control inside a page that has the following modal popup extender:

<asp:Panel ID="pnl_Completed" runat="server">
    <asp:Image ID="exit_Completed" runat="server" ImageUrl="" />
    <h3 style="text-align:center;">Completed</h3>
    <asp:Panel ID="pnl_inner" runat="server">
    <table style="width:100%;height:100%" cellpadding="5px"> 
        <tr style="height:40px;">
            <td valign="top">Comment: </td>
            <td>
            <telerik:RadTextBox ID="txt_CompletedComment" runat="server" TextMode="MultiLine" Rows="6" Width="400" Height="100"></telerik:RadTextBox>        
            </td>
        </tr>
        <tr style="height:40px;">
        <td colspan="2" align="center"><asp:Button id="btn_SaveCompleted" runat="server" Text="Complete" OnClick="btn_SaveCompleted_Click" /></td>
        </tr>
    </table> 
    </asp:Panel>

</asp:Panel>
<cc1:ModalPopupExtender ID="ModalPopupExtender_Completed" runat="server"  PopupControlID="pnl_Completed" CancelControlID="exit_Completed" TargetControlID="dummy_btn_Completed" >
</cc1:ModalPopupExtender>

<asp:Button id="dummy_btn_Completed" runat="server" CssClass="display_none" />

I want to show a messagebox on btn_SaveCompleted_Click event when the textbox is empty I have tried this:

 If txt_CompletedComment.Text.Trim().Length = 0 Then
            ScriptManager.RegisterStartupScript(Me, Me.GetType, "key", "alert('Please enter a comment.');", True)
 End If

but this doesnt work it just hides the modal popup extender, with no errors. Am I doing it wrong? Is there any other way to show it?


回答1:


Just use JavaScript, there a bunch of ways to do it here is one example:

<asp:Button id="btn_SaveCompleted" runat="server" Text="Complete"  
   OnClientClick="return ValidateTheTextbox();"OnClick="btn_SaveCompleted_Click" />


<script>
     function ValidateTheTextbox()
     {
          var txtbox = document.getElementById('<%= txt_CompletedComment.ClientID %>');
          if(txtbox.value=="")
          {
              alert('Please enter a comment.');
              return false; //suppress the submit button
          }
          return true; //let the form submit
     }
</script>


来源:https://stackoverflow.com/questions/14235533/showing-message-box-on-controls-modal-popup-extender

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!