C# .NET - modal popup not working - Asked By abinav shankar on 06-Feb-12 12:34 AM

Hi

I want to get a Modal popup and I used the following code shown below( and pl check the attachment for more details) and tell me where I went wrong I used the script manager in my master page .
<table class="style1">
    <tr>
      <td>
         </td>
      <td>
         </td>
      <td>
         </td>
      <td>
         </td>
    </tr>
    <tr>
      <td width="20%">
         </td>
      <td width="60%" colspan="2">
        <asp:GridView ID="grdApproval" runat="server" AutoGenerateColumns="False" 
          HeaderStyle-CssClass="tblBackground" HeaderStyle-Font-Bold="true" 
          HeaderStyle-ForeColor="White"
            
          <Columns>
            <asp:TemplateField HeaderText="Associate ID">
              <ItemTemplate>
                <asp:LinkButton ID="lnkAssId" Text='<%# Eval("associate_id") %>' runat="server" 
                  onclick="lnkAssId_Click">LinkButton</asp:LinkButton>
              </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Associate Name">
              <ItemTemplate>
                <asp:Label ID="lblAssoName" Text='<%# Eval("associate_fname") %>' runat="server"></asp:Label>
              </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Department">
              <ItemTemplate>
                <asp:Label ID="lblDepartment" Text='<%# Eval("dept_name") %>' runat="server"></asp:Label>
              </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Designation">
              <ItemTemplate>
                <asp:Label ID="lblDesignation" Text='<%# Eval("desig_name") %>' runat="server"></asp:Label>
              </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Leave Type">
              <ItemTemplate>
                <asp:Label ID="lblLeaveType" Text='<%# Eval("leave_type") %>' runat="server"></asp:Label>
              </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="From">
              <ItemTemplate>
                <asp:Label ID="lblFrom" Text='<%# Eval("from_date") %>' runat="server"></asp:Label>
              </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="To">
              <ItemTemplate>
                <asp:Label ID="lblTo" Text='<%# Eval("to_date") %>' runat="server"></asp:Label>
              </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Approve">
              <ItemTemplate>
                <asp:LinkButton ID="lnkApprove" runat="server" onclick="lnkApprove_Click">Approve</asp:LinkButton>
                  
              </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Reject">
              <ItemTemplate>
                <asp:LinkButton ID="lnkReject" runat="server" onclick="lnkReject_Click">Reject</asp:LinkButton>
                  
              </ItemTemplate>
            </asp:TemplateField>
          </Columns>
        </asp:GridView>
      </td>
      <td width="20%">
        <asp:Label ID="Label3" runat="server" Text="Label" Visible="False"></asp:Label>
        <asp:ValidationSummary ID="ValidationSummary1" runat="server" 
          ShowMessageBox="True" ShowSummary="False" ValidationGroup="a" />
      </td>
    </tr>
    <tr>
      <td width="20%">
          
      </td>
      <td width="60%" colspan="2">
        <%--</form>--%>
      <asp:Button ID="btnShowPopup" runat="server" style="display:none" />
</td>
      <td width="20%">
      <asp:Panel ID="pnlpopup" runat="server" BackColor="White" Height="150px" Width="400px" style="display:none">
<table width="100%" style="border:Solid 3px #D55500; width:100%; height:100%" cellpadding="0" cellspacing="0">
<tr style="background-color:#D55500">
<td colspan="2" style=" height:10%; color:White; font-weight:bold; font-size:larger" align="center">
  Associate Details</td>
</tr>
<tr>
<td align="right">
  Reject Reason:
</td>
<td>
<asp:TextBox ID="txtRejreason" runat="server" TextMode="MultiLine"/>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button ID="btnOk" CommandName="Update" runat="server" Text="Ok" 
    onclick="btnOk_Click1" CssClass="btnStyle"/>
</td>
</tr>
</table>
</asp:Panel>
      <cc1:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="btnShowPopup" PopupControlID="pnlpopup"
CancelControlID="btnCancel" BackgroundCssClass="modalBackground">
</cc1:ModalPopupExtender>


Code behind

protected void lnkReject_Click(object sender, EventArgs e)
   {
     try
     {
       LinkButton lnkReject = (LinkButton)sender;
       GridViewRow gvRowApprove = (GridViewRow)lnkReject.NamingContainer;
       LinkButton lnkAssid = (LinkButton)gvRowApprove.FindControl("lnkAssId");
       Label lblleaveType = (Label)gvRowApprove.FindControl("lblLeaveType");
       int leaveId = objApproveOrReject.getLeaveReqId(lnkAssid.Text.Trim(), "pending", lblleaveType.Text);
       Session["LeaveType"] = lblleaveType.Text;
       Session["leaveId"] = leaveId;
       this.ModalPopupExtender1.Show();
       //string url = "lms_Rejection.aspx";
       //ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "openPopup", "window.open('" + url + "','_blank','height=400,width=400,status=yes,toolbar=no,menubar=no,location=yes,scrollbars=yes,resizable=no,titlebar=no' );", true);
     }
     catch (Exception ex)
     {
       throw (ex);
     }
   }

Pl help me it very urgentNew folder (2).zip
[)ia6l0 iii replied to abinav shankar on 06-Feb-12 09:07 AM
Couple of things that I could quickly notice:

a) I don't see the variable "url" defined anywhere. 
b) Do not catch and throw exceptions. You lose the stacktrace. So catch, and then just throw.

So, Instead of 
catch (Exception ex) 

  throw ex;


Use,
catch (Exception ex) 

  //do whatever you want with the exception
  throw;


And also after you render this page, right-click on the page, and see the view source. That would give you more information on the actual script errors.

Hope this helps.