I'm aware you are using Telerik Controls here, and I am not sure if that introduces anything "unique" into this situation: the code shown here is what I would write in Windows Forms.
Your code for 'Disposed is executing
after the WindowDocument is closed and its 'Dispose handler has executed: so, the contents of any Controls within it, and the Controls within Controls, etc., like a TextBox in a UserControl, are ... gone.
I strongly suggest you handle the WindowDocument's 'Closing event, and have a simple public variable (or Property) in your UserControl that will be accessed by its Parent container when the Parent closes:
public bool IsDirty()
{
return textBox1.Text != clean;
}
And, in the Form/DocumentWindow:
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (test1.IsDirty)
{
if (ShowDialog("Do you want save form?") == DialogResult.Yes)
{
}
else
{
e.Cancel = true;
}
}
}
I find your use of 'test for both the
name of the UserControl, and in the Form code as a
variable name for an instance of 'DocumentWindow is very confusing, and I predict this will be a source of confusion for anyone trying to use/read your code ... including yourself when you look at your code in the future.
It doesn't
cost you anything to use
descriptive unique names, and it's an important skill/habit to develop.