Click here to Skip to main content
15,884,177 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
Can I use this Code as it is in Asp.net , I mean Can I Use Dialog Result and Message box in Asp.net??

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;
                    cmdupdate.ExecuteNonQuery();
                    lblMessage.Text = "Updated Successfully";
                }
                else { lblMessage.Text = "Not updated!!"; }//end else

            }//end if
            else
            {
                //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;
                cmdinsert.ExecuteNonQuery();
                lblMessage.Text = "File Uploaded Successfully";



            }
Posted
Updated 2-Apr-17 6:06am
Comments
[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?

You cannot use MessageBox result in Asp.net, 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" />

Javascript
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
           }
           else
           {
               // do other action
           }
       }
 
Share this answer
 
Comments
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 asp.net 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.
aspx:
<asp:LinkButton ID="ModalDummy" runat="server" />
<ajaxToolkit:ModalPopupExtender ID="ModalDummy_ModalPopupExtender" runat="server" BehaviorID="ModalDummy_ModalPopupExtender" TargetControlID="ModalDummy" PopupControlID="PanelPopup">
</ajaxToolkit:ModalPopupExtender>
<asp:Panel ID="PanelPopup" runat="server" DefaultButton="ButtonContactSend">
    your popup
</asp:Panel>



code behind
ModalDummy_ModalPopupExtender.Show();
 
Share this answer
 
Comments
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
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.
 
Share this answer
 
Comments
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, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900