473,378 Members | 1,334 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Dialog form closes unexpectedly

lotus18
866 512MB
Hello folks

I have a form with textboxes to input and it is showed as modal form (form 1.showDialog). I created a validation for my form and it should not save unless all the fields are filled up (e.g. MessageBox.Show("Please fill up all the fields", "Unable to save", MessageBoxButtons.OK, MessageBoxIcon.Information). Now, my problem is when I leave blank on one of the textboxes, of course a messagebox will pop up but after that it closes my form. Any suggestions will be greatly appreciated.

BTW, I'm using vb.net

Rey Sean
Jun 10 '08 #1
9 3640
r035198x
13,262 8TB
Post your validation code.
Jun 10 '08 #2
lotus18
866 512MB
Here it is

Expand|Select|Wrap|Line Numbers
  1.  If Len(txtTitle.Text) = 0 Then
  2.             MessageBox.Show("Please input course title.", REQUIRED, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  3.             txtTitle.Focus()
  4.             Exit Sub
  5.         ElseIf Len(txtDescription.Text) = 0 Then
  6.             MessageBox.Show("Please input course description.", REQUIRED, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  7.             txtDescription.Focus()
  8.             Exit Sub
  9.         End If
  10.  
I tried this and it will only work if the form is not in modal.

Rey Sean
Jun 10 '08 #3
vijayB
40
You might have written exit function or exit sub statement after validating the controls.
Try removing those statements.
Jun 10 '08 #4
lotus18
866 512MB
You might have written exit function or exit sub statement after validating the controls.
Try removing those statements.
Hi

If I'm not going to add exit sub statement it will just save the new record.

Rey Sean
Jun 10 '08 #5
vijayB
40
Hi

If I'm not going to add exit sub statement it will just save the new record.

Rey Sean

plz check the sub/function in which u have written the above code.
Try code execution with debug points and check out the flow.
if possible share the sub/function code.
Jun 10 '08 #6
lotus18
866 512MB
plz check the sub/function in which u have written the above code.
Try code execution with debug points and check out the flow.
if possible share the sub/function code.
I think that there's nothing wrong with my sub procedures. Like what I said on my previous post (post #3) it will only work and its fine when the form is not in modal mode, i want to achieve it with modal.

Rey Sean
Jun 10 '08 #7
Plater
7,872 Expert 4TB
Things go a little different in "modal" mode.
Soemtimes buttons get automatically linked to "close" events. If you look at the properties of your form there are like "AcceptButton" and "CancelButton". sometimes those get filled in.
The same thing happens when using MessageBox, since it returns a dialog result, sometimes the return result of THAT is applied to the modal form and the form gets closed.

Also, there should be NO reason for you to have to use exit sub in that situation. Check and use correct if-then-elseif logic. If you really need to, you can apply a state variable to alert you that something has gone wrong.
Jun 10 '08 #8
lotus18
866 512MB
Things go a little different in "modal" mode.
Soemtimes buttons get automatically linked to "close" events. If you look at the properties of your form there are like "AcceptButton" and "CancelButton". sometimes those get filled in.
The same thing happens when using MessageBox, since it returns a dialog result, sometimes the return result of THAT is applied to the modal form and the form gets closed.
Yes you are right. I have almost forgotten it.
Also, there should be NO reason for you to have to use exit sub in that situation. Check and use correct if-then-elseif logic. If you really need to, you can apply a state variable to alert you that something has gone wrong.
What do you mean by state variable?

Rey Sean
Jun 11 '08 #9
Rich B
1
An old question, but without a correct answer.

Because this sub is designated as the "Accept button" handler, the designer assigns an "OK" status to the DialogResult automatically for this sub. To exit the sub without closing the dialog, you must change the DialogResult to NONE.

E.g.
Expand|Select|Wrap|Line Numbers
  1. If (not validated) Then
  2.   Me.DialogResult = Windows.Forms.DialogResult.None
  3.   Exit Sub
  4. End If
Aug 26 '11 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Jim Heavey | last post by:
Hello If I have created a form which will be used as a dialog box, how do I get the results passed pack from the dialog box? I tried this DialogResult rslt = frm.ShowDialog(); I do not get...
2
by: steve bull | last post by:
I have built what I think should be a dialog box. It contains 4 tabbed panes for generating a range of colors. Each tabbed pane consists of a panel with all the widgets on them including the OK and...
1
by: Eitan | last post by:
Hello, I have some questions about dialog-box 1) I see that when I use dialog-box (by window.showModalDialog), and the dialog is an aspx page - it opens a new session, can I stay at the same...
2
by: proit_123 | last post by:
I am working on a windows forms application and have the following requirement. · I need to display a modeless dialog from the main form. o This allows user to continue to work with the...
8
by: proit_123 | last post by:
I am working on a windows forms application and have the following requirement. I have two projects in my application Project A and Project B. And Project A has the reference of Project B. I...
2
by: John Brock | last post by:
At work we are using a virtual desktop manager called AltDesk (http://www.astonshell.com/), and it is causing a weird and extremely annoying problem with the VB.NET application I am developing. ...
4
by: rdemyan | last post by:
I'm using code from the following web page to open the API Browse Folder dialog http://www.mvps.org/access/api/api0002.htm It all works fine. But if the dialog box is open and the user closes...
11
by: Zytan | last post by:
I have created a new form from the main form. When I close the main form with the 'x' close button, its Form.FormClosed event is run, but not the dialog's. Is this normal? It is ok /...
3
by: Johnson | last post by:
I'm not sure if this is an IIS 5.1 issue or ASP.NET issue, or Visual Studio 2008 issue -- thus posting to 3 groups. Please don't be offended. The problem I'm encountering is that Visual Studio...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.