You need to do this with Javascript. If you want to dynamically create the javascript you can do that with the RegisterStartupScript command. That'l do donkey, that'l do
Mark
If you are unsure of forum etiquette check here faq796-2540
Well it depends on when you want to pop up the message box. If you want it on a button click then you add an attribute value for the onclick event. Returning false if no to say don't submit the form so the serverside event won't happen.
Or you can add the javascript to the page then store the result in a hidden textbox and get that value server side when you need it.
If you can give a bit of background info I can give you a more specific example. That'l do donkey, that'l do
Mark
If you are unsure of forum etiquette check here faq796-2540
Hi Mark!
The purpose of the web form is to add a Category record to the “Categories” table in the NorthWind database. Once all the fields information was filled and the user clicks Submit (Add customer), a message box should appear asking “Add product”. If the user clicks “yes”, then the appropriate panel control for “Categories” is displayed + a submit button to add the product. When the user clicks that button, the product is inserted to the “Products” table and the user is asked again (with a message box) whether to add another product etc. Once the user clicks “no”, the last product is added to the database.
This demanded to include the using statement for the “System.Windows.Forms.dll”.
But whenever clients press the “Add customer” button, the message box appears on the IIS computer and not on their machine. I’d rather find a solution using MessageBox but right now I can’t see any clue.
There is no solution using messagebox. Remember that you are coding a serverside application not a desktop one. Any code that you write is run on the server. Some of that code in the case of a webform sends a stream of data down to the client where the browser looks at the data stream and renders that data stream as the browser sees fit.
So when you want something to happen on the client you add a control on the serverside that appends data onto that data stream that is being sent down. Or you can manually add data to that stream. One of the methods you can do that is to use the RegisterStartupScript command.
What this does is to append the exact string you send down right before the closing tag for the form. In most cases I have seen so far this is used to send down a piece of javascript. The browser then see's that javascript and does something with it.
Sorry for being so simplistic here but it really helps if you can understand this concept.
Now in your case we aren't going to use RegisterStartupScript. We are still going to append some data to that stream going to the client, just using a different method.
We are going to use the attributes property that every server control has. The following code should be placed in the page_load event under a not ispostback check.
Button1.Attributes.Add("onclick", "return (confirm('do you want to?'))"
Now to explain. Attributes is a collection so we access the add method of that collection to add an attribute. Simple enough. The parameters for an add include the Key and the Value. The key you want to specify is onclick for the javascript onclick event. The value is what we want to happen on click. Basically a confirm message box. By putting return in front we decide what will happen next. Should the client click Cancel in the messagebox the clientside onclick returns a false and so does not submit the form. If the client clicks OK then onclick returns true and the form is submitted.
Then server side in the event handler for the button you can add the Category and display the Product panel.
Do the same thing for the product ok button as we did here and you'll be fine.
I definetely hoped this helped ya my fingers are tired. j/k
Good luck That'l do donkey, that'l do
Mark
If you are unsure of forum etiquette check here faq796-2540
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.