Click here to Skip to main content
15,893,486 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,i have a button ,i want that when i click on that button the data should be saved in the database as well as at the same time a modal popup
should display the customerid .i have written the code as

<asp:button id="save1" runat="server" onclick="Button4_Click" style=""z-index:" mode="hold" xmlns:asp="#unknown" />           left: 740px; position: absolute; top: 304px" Text="save"/>

<asp:panel id="panel" runat="server" xmlns:asp="#unknown"></asp:panel>

                <ajaxtoolkit:modalpopupextender id="MPE" runat="server" targetcontrolid="save1" xmlns:ajaxtoolkit="#unknown">
                PopupControlID="panel" DropShadow="true"
                BackgroundCssClass="modalBackground/>
</ajaxtoolkit:modalpopupextender>

protected void Button4_Click(object sender, EventArgs e)
   {
       string id = TextBox1.Text;
       string name = TextBox2.Text;
       string cn = "Data Source=hcl;Initial Catalog=mydata;Integrated Security=True";
       SqlConnection con = new SqlConnection(cn);
       SqlCommand cmd = new SqlCommand("insert into customer values (@id,@name)", con);
       con.Open();
       cmd.CommandType = CommandType.Text;
       cmd.Parameters.Add("@id", id);
       cmd.Parameters.Add("@name",name);

       cmd.ExecuteNonQuery();

       con.Close();
       CUSTID.Text = id.ToString();
       MPE.Show();
}


but it is not happening.even if i comment the MPE.Show() line a popup
is coming.i m not understanding what is happening plz help i want code using ajax as well as normal javascript.
Posted
Updated 31-Aug-10 7:38am
v3

If you read the documentation for ModalPopup[^] you will understand what is happening.
TargetControlID - The ID of the element that activates the modal popup.

If you look at the documentation you will see a sample for activating the ModalPopup from server-side code.
 
Share this answer
 
Comments
software_Engi08 31-Aug-10 14:02pm    
i have go through the answer provided by u but still i haven't got the actual answer. i think BehaviourID="" may do something but how i dont know .is it possible to save data into database and simultaneously showing modalpopup without using ajax give some code on that as well .
[no name] 31-Aug-10 16:07pm    
BehaviourID has nothing to do with your issue. I have given you the answer, shown you a link to an example. What more do you want? What don't you understand?
So your popup is showing, but the C# code doesn't appear to be executing? Perhaps try removing targetcontrolid="save1". I am guessing that the modal popup is intercepting the click event and so is prevent a postback (so your C# code isn't running). If you remove that, but keep the MPE.Show(), then the modal should popup after your C# runs.
 
Share this answer
 

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