Click here to Skip to main content
14,494,281 members
Rate this:
Please Sign up or sign in to vote.
See more:
Can I use this Code as it is in , I mean Can I Use Dialog Result and Message box in

What I have tried:

DialogResult Dialog = MessageBox.Show(" The File is Already exist , Do you want to replace it?", Name, MessageBoxButtons.YesNo);
                if (Dialog == DialogResult.Yes)

                    SqlCommand cmdupdate = new SqlCommand("update Attcehments set Data=@Data,Semester='" + semester + "' where AttchName='" + Name + "'and CourseNum='" + course_number + "'", connection);
                    cmdupdate.Parameters.Add("@Data", SqlDbType.Binary).Value = bytes;
                    lblMessage.Text = "Updated Successfully";
                else { lblMessage.Text = "Not updated!!"; }//end else

            }//end if
                //insert the file into database

                string strQuery = "insert into Attcehments(AttchName, CourseNum,Semester, Data,Priority)  values ('" + Name + "','" + course_number + "','" + semester + "', @Data,'" + priority + "')";
                SqlCommand cmdinsert = new SqlCommand(strQuery, connection);
                cmdinsert.Parameters.Add("@Data", SqlDbType.Binary).Value = bytes;
                lblMessage.Text = "File Uploaded Successfully";

Updated 2-Apr-17 6:06am
[no name] 1-Apr-17 14:08pm
Sure you can use a messagebox. If, and only if, you have someone sitting in front of the webserver computer willing and able to sit there and wait for it to popup and click the Ok button which your user will never see.
Rawan Mansourr 1-Apr-17 14:42pm
what I can use instead of these Message box and dialog result?
Rate this:
Please Sign up or sign in to vote.

Solution 2

You cannot use MessageBox result in, it shall be replaced by confirm() function [^] in javascript, provided you will have to take care of your business logic and knowing how Asp page life cycle[^] works

Mark up
<asp:Button ID="Button1" OnClientClick="funCheck()" runat="server" Text="Button" OnClick="Button1_Click" />
    <asp:HiddenField ID="HiddenField1" runat="server" />

function funCheck() {
          var flag = confirm('The File is Already exist , Do you want to replace it?');
          var hdnfld = document.getElementById('<%= HiddenField1.ClientID %>');
          hdnfld.value = flag ? '1' : '0';

Code behind
protected void Button1_Click(object sender, EventArgs e)
           if (HiddenField1.Value == "1")
               // do some action
               // do other action
Rawan Mansourr 2-Apr-17 11:14am
It is working , Thank you very much.
Rawan Mansourr 2-Apr-17 11:15am
but ,please I have a question ; what the best syntax to show the alert in pages?, now I am using script message , it is well or no?
Karthik_Mahalingam 2-Apr-17 11:19am
there is only one syntax for alert();
there is nothing called as best syntax
what is script message?
Rawan Mansourr 2-Apr-17 11:23am
Thats it
string script = "alert(\"Coordinator Already Exsist\");";
ScriptManager.RegisterStartupScript(this, GetType(),
"ServerControlScript", script, true);

the second :
Response.Write("alert('please select the course and the Semester From Main page First!!');window.location='MainPage.aspx';");
Karthik_Mahalingam 2-Apr-17 11:28am
you should use the first one..

the second one will just display as text.
test it and see how it works.
Rawan Mansourr 2-Apr-17 11:33am
it works but not in the properly way , you mean to use the first one? , and the last question , how can I use the redirect or windows location if I use the first way , and thank you.
Karthik_Mahalingam 2-Apr-17 11:35am
string script = "alert('Coordinator Already Exsist'); window.location='yoururl.aspx'";
ScriptManager.RegisterStartupScript(this, GetType(),
"ServerControlScript", script, true);
Rawan Mansourr 2-Apr-17 12:05pm
it worked , Thank you
Karthik_Mahalingam 2-Apr-17 12:09pm
Rawan Mansourr 2-Apr-17 13:23pm
Please sir I have a question , when I use Script manager in the page load , every time I click to the page it is show , I need to show it once time , any way to do that? and thank you
Karthik_Mahalingam 2-Apr-17 21:10pm
Use page.ispostback condition
Rate this:
Please Sign up or sign in to vote.

Solution 3

<asp:LinkButton ID="ModalDummy" runat="server" />
<ajaxToolkit:ModalPopupExtender ID="ModalDummy_ModalPopupExtender" runat="server" BehaviorID="ModalDummy_ModalPopupExtender" TargetControlID="ModalDummy" PopupControlID="PanelPopup">
<asp:Panel ID="PanelPopup" runat="server" DefaultButton="ButtonContactSend">
    your popup

code behind
Rawan Mansourr 2-Apr-17 12:10pm
that's a rich answer ,thank you
Stein The Ruler 2-Apr-17 12:21pm
its just to show you that you don't have to use any javascript and keep it all .net
Rawan Mansourr 2-Apr-17 12:53pm
ok , that's fine.but it is give Unrecognized prefix ajaxtoolkit and the modalpopuo does not exist
Stein The Ruler 2-Apr-17 13:25pm
you can install it using nuget manager. command: Install-Package AjaxControlToolkit
Rawan Mansourr 2-Apr-17 13:34pm
ok ,nice , thank you
Rate this:
Please Sign up or sign in to vote.

Solution 1

You cannot use MessageBox in an ASP.NET app. Sure, it works on your machine. Deploy this to an actual web server and your code will sit there waiting for input that will never happen as the MessageBox will show up on a desktop on the SERVER, NOT THE CLIENT. Even if you log into the server console, you still won't see the MessageBox. It'll show up on a desktop that is not visible to the logged in user.

You're code needs to be completely overhauled to remove all these references to MessageBox and DialogResult. They have no meaning in an ASP.NET app.
Rawan Mansourr 1-Apr-17 14:41pm
ok , what I can use instead of these message box, and dialog box ?
Dave Kreskowiak 1-Apr-17 16:41pm
You have to do that stuff in your client-side javascript code. I don't know what you're doing but from what you posted, your client code isn't going to know anything about any files already existing.
Stein The Ruler 2-Apr-17 2:49am
I normally use ModalPopupExtender in the Ajax Control Toolkit

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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100