如何在标签上显示数据库值?

时间:2013-10-19 12:13:30

标签: c# html asp.net

这是HTML代码

    

<div id="form3">


    <asp:Label ID="Label1" runat="server" Text="Enter your E-mail Id:"></asp:Label>
    <asp:TextBox ID="usremailtxt" runat="server"></asp:TextBox>
    <asp:Button ID="Button1" runat="server" Text="Button1" onclick="Button1_Click1" style="height: 26px"/>
     <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
              <asp:Panel ID="pnlpopup" runat="server" BackColor="Red" Height="80px" Width="300px" Style="display: none" >  
                <table width="100%" style="border:Solid 3px #D55500; width:100%; height:100%" cellpadding="0" cellspacing="0">
                   <tr>
                    <td align="center" 
                      style=" height:0%; color:White; font-weight:bold; font-size:larger">
                       Your Password Is:<asp:Label ID="pouplbl" runat="server" Text=""></asp:Label>
                   </td>
                  </tr>
                </table>
              </asp:Panel>
            </ContentTemplate>
           </asp:UpdatePanel>
           <cc2:ModalPopupExtender ID="ModalPopupExtender2" runat="server" 
               targetcontrolid="Button1" 
               popupcontrolid="pnlpopup" 
               dropshadow="true" 
               OkControlID="btnclose" >
            </cc2:ModalPopupExtender>


</div>
</form>

这是C#代码

protected void Button1_Click1(object sender, EventArgs e)
{
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["connection"].ConnectionString);
    con.Open();
    SqlCommand cmd = new SqlCommand("select password from User_detail where email_id = @email_id", con);
    cmd.Parameters.AddWithValue("@email_id", usremailtxt.Text);
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    DataSet ds = new DataSet();
    da.Fill(ds);
    pouplbl.Text = ds.Tables[0].Rows[0]["password"].ToString();
    this.ModalPopupExtender2.Show();
    con.Close();
}

问题在于没有出现。

1 个答案:

答案 0 :(得分:0)

您应该在updatepanel下复制modalpopupextender代码。 和scriptmanager应该是第一个元素,把它放在body标签下。

&LT;

div id="form3">


    <asp:Label ID="Label1" runat="server" Text="Enter your E-mail Id:"></asp:Label>
    <asp:TextBox ID="usremailtxt" runat="server"></asp:TextBox>
    <asp:Button ID="Button1" runat="server" Text="Button1" onclick="Button1_Click1" style="height: 26px"/>
     <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
              <asp:Panel ID="pnlpopup" runat="server" BackColor="Red" Height="80px" Width="300px" Style="display: none" >  
                <table width="100%" style="border:Solid 3px #D55500; width:100%; height:100%" cellpadding="0" cellspacing="0">
                   <tr>
                    <td align="center" 
                      style=" height:0%; color:White; font-weight:bold; font-size:larger">
                       Your Password Is:<asp:Label ID="pouplbl" runat="server" Text=""></asp:Label>
                   </td>
                  </tr>
                </table>
              </asp:Panel>

           <cc2:ModalPopupExtender ID="ModalPopupExtender2" runat="server" 
               targetcontrolid="Button1" 
               popupcontrolid="pnlpopup" 
               dropshadow="true" 
               OkControlID="btnclose" >
            </cc2:ModalPopupExtender>

            </ContentTemplate>
           </asp:UpdatePanel>

</div>
</form>