When js write confirmation boxes Are frequently used, return confirm ('Are you sure? '), Or use attributes in the background code. add () to add the following, but when there is a need: click the button to execute a piece of code, there is a judgment in this section of code, when the conditions are met, the user is asked whether to confirm the submission. We don't seem to be doing this.
Can this happen? As follows:
Aspx page:
<% @ Page Language = "C #" AutoEventWireup = "true" CodeFile = "Default. aspx. cs" Inherits = "_ Default" %>
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> Untitled Page </title>
<Script type = "text/javascript" language = "javascript">
Function ShowConfirmation ()
{
If (confirm ("Are you want to show the value? ") = True)
{
// Calling the server side code after confirmation from the user
Document. getElementById ("btnAlelrt"). click ();
}
}
</Script>
</Head>
<Body>
<Form id = "form1" runat = "server">
<Div>
<Asp: TextBox ID = "txtDetails" runat = "server"> </asp: TextBox>
<Br/>
<Asp: Button ID = "btnDetails" runat = "server" Text = "GetValue" OnClick = "btnDetails_Click"/>
<Asp: Button ID = "btnAlelrt" runat = "server" Text = "GetDetails" OnClick = "btnAlelrt_Click"/>
<Br/>
<Br/>
</Div>
</Form>
</Body>
</Html>
Code Section:
Using System;
Using System. Data;
Using System. Configuration;
Using System. Web;
Using System. Web. Security;
Using System. Web. UI;
Using System. Web. UI. WebControls;
Using System. Web. UI. WebControls. WebParts;
Using System. Web. UI. HtmlControls;
Public partial class _ Default: System. Web. UI. Page
{
Protected void Page_Load (object sender, EventArgs e)
{
// Hide the button from users visibility
BtnAlelrt. Style. Add ("display", "none ");
}
Protected void btnDetails_Click (object sender, EventArgs e)
{
// Here some conditions
If (txtDetails. Text = "111111 ")
{
Page. ClientScript. RegisterStartupScript (this. GetType (), "showAl", "ShowConfirmation ();", true );
}
Else
{
// Do nothing!
}
}
Protected void btnAlelrt_Click (object sender, EventArgs e)
{
// Write your code
Page. ClientScript. RegisterStartupScript (this. GetType (), "showVal", "alert ('" + txtDetails. Text + "');", true );
}
}
PS: A small Demo, not original. Google came when I used it. I don't know if it is appropriate to store the homepage... (This is the second time for a newbie. it is not suitable to leave a comment. I want to change places !), Also, how can I fold and indent the code !!