473,407 Members | 2,326 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,407 software developers and data experts.

ASP.NET dialog box

Forgive me for a newbie question...

I'm using ASP.NET and C# for the code behind.

I've got a dialog box opening on my page with javascript and it is attached to a button on the page during the Page_Load event with:

Expand|Select|Wrap|Line Numbers
  1.             MyButton.Attributes.Add("onclick", "var strReturn; strReturn=window.showModalDialog('ChildWindow.aspx',null,'status:no;dialogHeight:220px;dialogHide:true;help:no;scroll:no');if (strReturn != null) document.getElementById('ResponseValue').value=strReturn;");
  2.  
Works beautifully when the user clicks the button. My question is: how can I get this dialog to open from the code? In other words, in my code behind I'm validating what the user has entered and if certain conditions aren't met, I want to prompt the user for input by opening this dialog box automatically without having them click the button.

How do I do this in the code behind?

Thanks.

Robert
Apr 29 '08 #1
5 1076
DrBunchman
979 Expert 512MB
Hi Robert,

You can use the following to fire a message box from your code:
Expand|Select|Wrap|Line Numbers
  1.  String sMessage = "Hello World!"; 
  2. String  myscript  = "alert('" & sMessage & "');";
  3. Page.ClientScript.RegisterStartupScript(Me.GetType(), "myscript", myscript, True)
  4.  
I've cribbed this for C# from my own VB so it may not by syntactically perfect but hopefully you can get the idea.

Hope this helps,

Dr B
Apr 29 '08 #2
r035198x
13,262 8TB
...
I've cribbed this for C# from my own VB so it may not by syntactically perfect but hopefully you can get the idea.

Hope this helps,

Dr B
Better make the last line

Expand|Select|Wrap|Line Numbers
  1.  Page.ClientScript.RegisterStartupScript(Me.GetType(), "myscript", myscript, true);
Apr 29 '08 #3
Thanks. Works just fine now.

On minor fix, though, for C#. The "Me.GetType()" was changed to "GetType()".

I very much appreciate your help.

Robert
Apr 29 '08 #4
r035198x
13,262 8TB
Thanks. Works just fine now.

On minor fix, though, for C#. The "Me.GetType()" was changed to "GetType()".

I very much appreciate your help.

Robert
Ah, I missed that as well. So much for trying to correct others.
Apr 29 '08 #5
DrBunchman
979 Expert 512MB
Thank you both for your corrections to my (obviously rather poor!) attempt to convert VB to C#.

Damn those semi-colons!

Dr B
Apr 29 '08 #6

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

Similar topics

1
by: Prosonman | last post by:
Hi, What is the best way to transfer variables to and from a dialog box? My project consists of a form with a number of controls, lets say three Labels, when a label is clicked it opens a dialog...
23
by: George | last post by:
Is there a way to customize the open file common dialog? I am trying to modify the button text so I can create a delete file common dialog. I need the same functionality of the open file common...
1
by: Carmine | last post by:
I'm currently writing a small program that churns on a repetitive task while displaying a progress & cancel modeless dialog. I've been having problems due to threadlocking, and I was wondering if...
4
by: Alexander | last post by:
Hi, I have written a program that takes on some operations much more time than I expected. As I have seen users clicking wildly on the screen to make something happen, I want to follow the...
6
by: bryanhobson | last post by:
I'm fairly new to c#, and I am just trying to work out how a 'properties' dialog works. Currently in my code, I have an object represented by the class 'Dog'. The dog object has several...
4
by: ronenk | last post by:
I have this code to load an authentication form once my app is loaded. I want the authentication form to be closed if a user is authenticated successfully and to give the option to close app on his...
10
by: Guadala Harry | last post by:
I have a modal dialog that currently does all of the following except item 4. 1. lets users select a graphic from a list of thumbnails (and when selected, displays the full-size image in a...
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 /...
0
by: Moezzie | last post by:
So ive got a bit of a problem here. Ive been searching the net about this for quite some time now but i just cant seem to figure out how to open a dialog that ive made in QtDesigner. Of corse i...
11
by: VK | last post by:
In the continuation of the discussion at "Making Site Opaque -- This Strategy Feasible?" and my comment at http://groups.google.com/group/comp.lang.javascript/msg/b515a4408680e8e2 I have...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.