Click here to Skip to main content
15,891,744 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
Hello, I am creating a web application in C#, .Net and ASPX. And I want to generate confirm popup in C# code to ask question from user randomly at some place and get reply in form of (yes, no) , (ok, cancel) , (true, false). Any help will be really appreciated.
Thank you
Posted
Comments
Suvendu Shekhar Giri 28-Nov-15 3:33am    
Anything you have tried so far?
Member 11656452 28-Nov-15 3:42am    
I have tried writing javascript confirm popup in C# but by using that, I am unable to get reply (ok/cancel) in some C# variable. Here is the code

Page.ClientScript.RegisterStartupScript(Page.GetType(), "Message Box", "<script language='javascript'> confirm('This is confirm popup')</script>");
[no name] 28-Nov-15 7:16am    
This code is working for me. In which browser you are testing.
Secondly sure that above code is executed properly.

Thirdly when you are executing the code,either page_load or button click or ajax request. Tell us the environment details.
Member 11656452 28-Nov-15 20:53pm    
I am executing this code on button_click event. This code does not gives any error but I have found no way to get and use response further in C# code, like saving 'ok' or 'cancel' in some variable.
If you have used same code than please send me some code to store response of user in some variable.
Thank you
[no name] 29-Nov-15 1:19am    
Do you want to store confirm window response in client side or in server server side(code behind)?

1 solution

You do not want to do this in C#. When someone visits your page, your server compiles and executes your code and generates html and sends the html to the client and then disconnects. To prompt for information from user you need to use JavaScript and I would recommend against trying to use C# to execute the JavaScript because then you have to have a page postback which is bad form for this.

jQueryUI also has a nice .dialog() function that can be easily implemented for this. If you do ASP.Net you have to also use Javascript so may as well get used to it.
 
Share this answer
 
Comments
Member 11656452 28-Nov-15 21:01pm    
Actually I also want to use Javascript function for this but I am unable to complete required functionality using javascript.
The scenario in which I am working is "I am working on data-oriented application. I have 400 textboxes on my webform and data from those textboxes will be saved in SQL database. When the user clicks on SAVE BUTTON, than I want to implement a function which will check if any textbox is empty, if YES than ask from user that some textboxes are empty, do you still want to continue."
When I used C#, I will just use 2 for loops to set names of textboxes and check wether textbox is empty or not. In Javascript, I found no way to typecast some var to Textbox control, Like in C# we use FindControl("") function for typecasting. If you have any solution than please let me know.
Thank you
ZurdoDev 28-Nov-15 22:49pm    
jQuery can do it in one line. Google for jquery selectors to see your options. For example, give all your textboxes a class name of txtBoxes or something and then you can select them all like this:
$(".txtBoxes).

But there is also a jquery selector for the value as well so you could easily check to see if there are any empty textboxes.

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