can I use server control inside jquery modal popup

Last Reply 12 days ago By dharmendr

Posted 12 days ago

is it possible to execute click event from .cs file

<div class="modal" id="modalPopup"  >
    <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click"/>
</div>

 

You are viewing reply posted by: dharmendr 12 days ago.
Posted 12 days ago

Hi JGeorge,

Check this example. Now please take its reference and correct your code.

HTML

<asp:Label ID="Label1" runat="server" />
<div id="dialog" align="center" style="display: none">
    <table width="100%">
        <tr>
            <td>
                <asp:Label ID="lblcustom" runat="server" Text="Custom" Font-Names="Verdana" Font-Size="10pt"></asp:Label>
            </td>
            <td>
                <asp:RadioButton ID="rbcustom" runat="server" />
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <asp:GridView ID="grdview" runat="server" AutoGenerateColumns="false" Width="100%">
                    <Columns>
                        <asp:TemplateField ItemStyle-HorizontalAlign="Center">
                            <HeaderTemplate>
                                <asp:CheckBox ID="chkSelectAll" runat="server" OnCheckedChanged="chkSelectAll_CheckedChanged" AutoPostBack="true" />
                            </HeaderTemplate>
                            <ItemTemplate>
                                <asp:CheckBox ID="chkDelete" runat="server" />
                            </ItemTemplate>
                            <ItemStyle HorizontalAlign="Center"></ItemStyle>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="User Id" InsertVisible="False" Visible="False">
                            <ItemTemplate>
                                <asp:Label ID="lblUserId" runat="server" Text='<%# Eval("Id") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="FirstName" HeaderStyle-CssClass="headertext" ItemStyle-CssClass="name">
                            <ItemTemplate>
                                <asp:Label ID="LbFirstName" runat="server" Text='<%# Eval("First_Name") %>'></asp:Label>
                            </ItemTemplate>
                            <HeaderStyle />
                            <ItemStyle />
                        </asp:TemplateField>

                    </Columns>
                </asp:GridView>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click"/>
            </td>
        </tr>
    </table>
</div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.9/jquery-ui.js" type="text/javascript"></script>
<link href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.9/themes/blitzer/jquery-ui.css"
    rel="stylesheet" type="text/css" />
<script type="text/javascript">
    $(function () {
        $("#btnShow").click(function () {
            ShowPopup();
        });
    });

    function ShowPopup() {
        $("#dialog").dialog({
            title: "jQuery Dialog",
            modal: true
        });
        $("#dialog").parent().appendTo($("form:first"));
    };
</script>
<input type="button" id="btnShow" value="Show Popup" />

Code

C#

protected void Page_Load(object sender, EventArgs e)
{
    if (!this.IsPostBack)
    {
        this.BindGrid();
    }
}

protected void Button1_Click(object sender, EventArgs e)
{    
    ClientScript.RegisterStartupScript(this.GetType(), "Popup", "ShowPopup();", true);
}
protected void chkSelectAll_CheckedChanged(object sender, EventArgs e)
{
    try
    {
        CheckBox chkSelectAll = (CheckBox)grdview.HeaderRow.FindControl("chkSelectAll");
        for (int i = 0; i < grdview.Rows.Count; i++)
        {
            CheckBox chkDelete = (CheckBox)grdview.Rows[i].FindControl("chkDelete");
            switch (chkSelectAll.Checked)
            {
                case true:
                    chkDelete.Checked = true;
                    break;
                case false:
                    chkDelete.Checked = false;
                    break;
            }
        }
    }
    catch (Exception ex)
    {
        Label1.Visible = true;
        Label1.Text = ex.Message;
        Label1.ForeColor = System.Drawing.Color.Red;
    }
    ClientScript.RegisterStartupScript(this.GetType(), "Popup", "ShowPopup();", true);
}

protected void BindGrid()
{
    DataTable dt = new DataTable();
    dt.Columns.AddRange(new DataColumn[3] { new DataColumn("Id"), new DataColumn("First_Name") });
    dt.Rows.Add(1, "John Hammond");
    dt.Rows.Add(2, "Mudassar Khan");
    dt.Rows.Add(3, "Suzanne Mathews");
    dt.Rows.Add(4, "Robert Schidner");
    grdview.DataSource = dt;
    grdview.DataBind();
}

VB.Net

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        If Not Me.IsPostBack Then
            Me.BindGrid()
        End If
    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
        ClientScript.RegisterStartupScript(Me.GetType(), "Popup", "ShowPopup();", True)
    End Sub

    Protected Sub chkSelectAll_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs)
        Try
            Dim chkSelectAll As CheckBox = CType(grdview.HeaderRow.FindControl("chkSelectAll"), CheckBox)
            For i As Integer = 0 To grdview.Rows.Count - 1
                Dim chkDelete As CheckBox = CType(grdview.Rows(i).FindControl("chkDelete"), CheckBox)
                Select Case chkSelectAll.Checked
                    Case True
                        chkDelete.Checked = True
                    Case False
                        chkDelete.Checked = False
                End Select
            Next

        Catch ex As Exception
            Label1.Visible = True
            Label1.Text = ex.Message
            Label1.ForeColor = System.Drawing.Color.Red
        End Try

        ClientScript.RegisterStartupScript(Me.GetType(), "Popup", "ShowPopup();", True)
    End Sub

    Protected Sub BindGrid()
        Dim dt As DataTable = New DataTable()
        dt.Columns.AddRange(New DataColumn(2) {New DataColumn("Id"), New DataColumn("First_Name")})
        dt.Rows.Add(1, "John Hammond")
        dt.Rows.Add(2, "Mudassar Khan")
        dt.Rows.Add(3, "Suzanne Mathews")
        dt.Rows.Add(4, "Robert Schidner")
        grdview.DataSource = dt
        grdview.DataBind()
    End Sub