Click here to Skip to main content
15,889,876 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have this code and what I want is to fetch data from database and assign the data to the label in the popup.I have add a click event to the "addnew" button but code behind is not working because of the client side model pop.Is there any way to do this?


ASP.NET
<form id="form1" runat="server">
<div>
<asp:ScriptManager runat="server"></asp:ScriptManager>
   <asp:Button ID="addnew" OnClick="addnew_Click" runat="server" Text="Add New" CssClass="btn btn-warning"  />

    <asp:Panel ID="panelRegister" CssClass="modalPopup form-control" runat="server" Style="display: none;">
        <div class="row" style="margin-removed 5px">
            <div class="col-xs-8">
                <asp:Label ID="Label1" runat="server" Font-Size="Smaller"></asp:Label>
            </div>
            <div class="col-xs-4"></div>
        </div>
        <br />

        <div class="row">
            <div class="col-xs-3"></div>
            <div class="col-xs-3">
                <asp:Button ID="cancel" runat="server" CssClass="btn btn-default" Text="Ok" CausesValidation="False" />
            </div>
            <div class="col-xs-3"></div>
        </div>
        <br />
    </asp:Panel>
    <ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender1"  runat="server" BackgroundCssClass="modalBackground" PopupControlID="panelRegister" TargetControlID="addnew"></ajaxToolkit:ModalPopupExtender>
</div>
</form>


code behind function I have used

SQL
protected void addnew_Click(object sender, EventArgs e)
        {
            string sqlsel = "SELECT name FROM dbo.patient nic = '568921452' ";
            SqlCommand com = new SqlCommand(sqlsel, DBcon.connection());
            SqlDataReader dr = com.ExecuteReader();
             
            if(dr.Read())
            {
                Label1.Text = dr[0].ToString();
            }
        }
Posted
Updated 13-Nov-15 4:59am
v2
Comments
ZurdoDev 13-Nov-15 11:46am    
Why doesn't Label1.Text = dr[0].ToString(); work?
uglsa 13-Nov-15 12:43pm    
addnew_Click function doesn't trigger when the addnew button clicked
Rajesh Pandya 2-Dec-15 8:05am    
Use two separate button for do this. On add new button click use javascript function and in javascript function call another button click and do the code behinde stuff in that click event and also use updatepanel with that. If you need sample code then feel free to ask me

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900