forum

Home / DeveloperSection / Forums / inserting data to DB on click of button placed in a jquery pop-up window

inserting data to DB on click of button placed in a jquery pop-up window

Rashmi S 2097 09-Dec-2014
hi... I'm creating pop-up window to allow visitors to post their feedbacks. In master page, i used DIV tag for feedback GUI, on click of "Feedback" option ,im displaying feedback DIV as a popup window using jquery dialog method. on click of "Send" button, i wrote code for inserting data to DB. In webform created using masterpage, "Send" button click event is not triggering, but in webpage without masterpage , "Send " button event is triggering..

I want the code to work in childpages...

Masterpage code:
source code:
<script type="text/javascript">
<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/start/jquery-ui.css"
        rel="stylesheet" type="text/css" />
 $("[id*=btnPopup]").live("click", function () {
        $("#modal_dialog").dialog({
            title: "POST FEEDBACK",
            width: "600",
            modal: true,
            buttons: {
                Send: function () {
                    //$("[id*=Button1]").click();
                    $(document.getElementById('<%= Button1.ClientID %>')).click();
                },
                Close: function () {
                    $(this).dialog('close');
                }
            },
            open: function (type, data) { $(this).parent().appendTo("form"); },
            close: function (type, data) { $(this).parent().replacewith(""); }
        });
        return false;
    });
</script>
<li><asp:LinkButton ID="btnPopup" runat="server" Text="Feedback">Feedback</asp:LinkButton></li>
<div id="modal_dialog" style="display: none;width:auto;">
                                 <table style="width:100%;">
        <tr>
            <td align="center">
                <strong style="font-size: medium">FEEDBACK</strong></td>
        </tr>
        <tr>
            <td style="height: 30px">
                <hr size="3" color="#DA6BB6"/></td>
        </tr>
        <tr>
            <td>
            
                <table style="width:100%;">
                    <tr>
                        <td style="width: 117px; font-size: medium; color: #800000;" bgcolor="#F8DDBA">
                            Name</td>
                        <td>
                            <asp:TextBox ID="txtName" runat="server" Width="350px"></asp:TextBox>
                        </td>
                        <td>
                            &nbsp;</td>
                    </tr>
                    <tr>
                        <td style="width: 117px; font-size: medium; color: #800000;" bgcolor="#F8DDBA">
                            Email ID</td>
                        <td>
                            <asp:TextBox ID="txtEmailId" runat="server" Width="350px"></asp:TextBox>
                        </td>
                        <td>
                            &nbsp;</td>
                    </tr>
                    <tr>
                        <td style="width: 117px; font-size: medium; color: #800000;" bgcolor="#F8DDBA">
                            Contact Number</td>
                        <td>
                            <asp:TextBox ID="txtContactNo" runat="server" Width="350px"></asp:TextBox>
                        </td>
                        <td>
                            &nbsp;</td>
                    </tr>
                    <tr>
                        <td style="width: 117px; font-size: medium; color: #800000;" bgcolor="#F8DDBA" 
                            valign="top">
                            Feedback</td>
                        <td>
                            <asp:TextBox ID="txtFeedback" runat="server" Rows="8" TextMode="MultiLine" 
                                Width="350px"></asp:TextBox>
                        </td>
                        <td>
                            &nbsp;</td>
                    </tr>
                    <tr>
                        <td style="width: 117px; font-size: medium; color: #800000;" bgcolor="#F8DDBA">
                            &nbsp;</td>
                        <td>
                            &nbsp;<asp:Button ID="Button1" runat="server" style = "display:none" OnClick = "Button1_Click" 
                                Text="Post"  />
                        </td>
                        <td>
                            &nbsp;</td>
                    </tr>
                </table>
            
            </td>
        </tr>
        <tr>
            <td>
            
                &nbsp;</td>
        </tr>
</table>
</div>
protected void Button1_Click(object sender, EventArgs e)
        {
            if (b.Feedback_Add(txtName.Text, txtEmailId.Text, txtContactNo.Text, txtFeedback.Text, DateTime.Now.ToShortDateString()) == 1)
                Response.Write("<script>alert('Feedback sent successfully.')</script>");
            else
                Response.Write("<script>alert('ERROR in sending feedback.')</script>");
            txtContactNo.Text = "";
            txtEmailId.Text = "";
            txtFeedback.Text = "";
            txtName.Text = "";
        }

This is not working....!

Webpage without masterpage:
<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/start/jquery-ui.css"
        rel="stylesheet" type="text/css" />
<script type="text/javascript">
    $(document).ready(function () {
        $("#modal_dialog").dialog({
            title: "jQuery Dialog Popup",
            width: "600",
            modal: true,
            buttons: {
                Send: function () {
                    //$("[id*=Button1]").click();
                    $(document.getElementById('<%= Button1.ClientID %>')).click();
                },
                Close: function () {
                    $(this).dialog('close');
                }
            },
            open: function (type, data) { $(this).parent().appendTo("form"); },
            close: function (type, data) { $(this).parent().replacewith(""); }
        });
        return false;
    });
</script>
<body>
    <form id="form1" runat="server">
    <div>
       <div id="modal_dialog" style="display: none;width:auto;">
                                 <table style="width:100%;">
        <tr>
            <td align="center">
                <strong style="font-size: medium">FEEDBACK</strong></td>
        </tr>
        <tr>
            <td style="height: 30px">
                <hr size="3" color="#DA6BB6"/></td>
        </tr>
        <tr>
            <td>
            
                <table style="width:100%;">
                    <tr>
                        <td style="width: 117px; font-size: medium; color: #800000;" bgcolor="#F8DDBA">
                            Name</td>
                        <td>
                            <asp:TextBox ID="txtName" runat="server" Width="350px"></asp:TextBox>
                        </td>
                        <td>
                            &nbsp;</td>
                    </tr>
                    <tr>
                        <td style="width: 117px; font-size: medium; color: #800000;" bgcolor="#F8DDBA">
                            Email ID</td>
                        <td>
                            <asp:TextBox ID="txtEmailId" runat="server" Width="350px"></asp:TextBox>
                        </td>
                        <td>
                            &nbsp;</td>
                    </tr>
                    <tr>
                        <td style="width: 117px; font-size: medium; color: #800000;" bgcolor="#F8DDBA">
                            Contact Number</td>
                        <td>
                            <asp:TextBox ID="txtContactNo" runat="server" Width="350px"></asp:TextBox>
                        </td>
                        <td>
                            &nbsp;</td>
                    </tr>
                    <tr>
                        <td style="width: 117px; font-size: medium; color: #800000;" bgcolor="#F8DDBA" 
                            valign="top">
                            Feedback</td>
                        <td>
                            <asp:TextBox ID="txtFeedback" runat="server" Rows="8" TextMode="MultiLine" 
                                Width="350px"></asp:TextBox>
                        </td>
                        <td>
                            &nbsp;</td>
                    </tr>
                    <tr>
                        <td style="width: 117px; font-size: medium; color: #800000;" bgcolor="#F8DDBA">
                            &nbsp;</td>
                        <td>
                            &nbsp;<asp:Button ID="Button1" runat="server" style = "display:none" OnClick = "Button1_Click" 
                                Text="Post"  />
                        </td>
                        <td>
                            &nbsp;</td>
                    </tr>
                </table>
            
            </td>
        </tr>
        <tr>
            <td>
            
                &nbsp;</td>
        </tr>
</table>
                             </div>
    </div>
    </form>
</body>
protected void Button1_Click(object sender, EventArgs e)
        {
            if (b.Feedback_Add(txtName.Text, txtEmailId.Text, txtContactNo.Text, txtFeedback.Text, DateTime.Now.ToShortDateString()) == 1)
            {
                Response.Write("<script>window.alert('Feedback sent successfully.');window.location='/Visitor/HomePage.aspx';</script>");
            }
            else
            {
                Response.Write("<script>window.alert('ERROR in sending feedback.');window.location='/Visitor/HomePage.aspx';</script>");
            }
            //System.Threading.Thread.Sleep(10000);
            txtContactNo.Text = "";
            txtEmailId.Text = "";
            txtFeedback.Text = "";
            txtName.Text = "";
            /
        }

This code is working....!

I want the code to execute in childpages
Any help appreciated..! 
Thank You...!


Updated on 09-Dec-2014

Can you answer this question?


Answer

0 Answers

Liked By