473,386 Members | 1,706 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,386 software developers and data experts.

Message Box in C# Web Application

ben
I have a web application whic connects to the database and populates a
datagrid based on 2 fields the user enters on the web form.
I have a try catch block to make sure that in case the user enters
values(dates) not found in database, then i redirect the user to the
origianl page where they enter the values.

I would like a message box saying they entered invalid dates(not a
check for date format, but that they entred dates which dont return
any values in the db, n hence the db error)

so far, i have this
catch
{

Response.Write("<script>window.alert('No Entries Found.')</script>");
}

I would like the user to be redirected to the date entry field after
clicking this messagebox.How do i do that? If i try to add
Response.Redirect("Main.aspx") after the response.write, it ignores
the message box and simply redirects, whic is not what i want.

Any inputs wud be appreciated

THanks
Nov 18 '05 #1
9 13055
Response.Redirect occurs on the server, while the Page is processing.
Therefore, if you put in any code that writes anything to the Page, it will
not happen, as the current Page is unloaded before it ever reaches the
browser. If you want the page to redirect on the client side (that is, after
the alert box pops up on the client), your simplest solution would be to use
JavaScript to do it (document.location = url;). If you need to do more
processing on the server prior to redirecting, you could use JavaScript to
post the form and do the Redirect on the server side.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"ben" <sk****@yahoo.com> wrote in message
news:ba**************************@posting.google.c om...
I have a web application whic connects to the database and populates a
datagrid based on 2 fields the user enters on the web form.
I have a try catch block to make sure that in case the user enters
values(dates) not found in database, then i redirect the user to the
origianl page where they enter the values.

I would like a message box saying they entered invalid dates(not a
check for date format, but that they entred dates which dont return
any values in the db, n hence the db error)

so far, i have this
catch
{

Response.Write("<script>window.alert('No Entries Found.')</script>");
}

I would like the user to be redirected to the date entry field after
clicking this messagebox.How do i do that? If i try to add
Response.Redirect("Main.aspx") after the response.write, it ignores
the message box and simply redirects, whic is not what i want.

Any inputs wud be appreciated

THanks

Nov 18 '05 #2

Kevin,
Thanks for ur immediate reply.
Can u plz post soem sample code for doing the document.location code, as
i m not familiar with this.
Thanks
Ben
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #3
ok...figured out the syntax for
window.document.location('blahblah.aspx')...
howevre it doe snot do anything n does not redirect either....

any ideas?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #4
> ok...figured out the syntax for
window.document.location('blahblah.aspx')...
howevre it doe snot do anything n does not redirect either....

any ideas?
Not really. It's just client-side JavaScript, and it will work if it is used
correctly. I have no idea how you've used it.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Ben Arthur" <sk****@yahoo.com> wrote in message
news:Oe**************@TK2MSFTNGP11.phx.gbl... ok...figured out the syntax for
window.document.location('blahblah.aspx')...
howevre it doe snot do anything n does not redirect either....

any ideas?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #5
ok...figured out the syntax for
window.document.location('blahblah.aspx')...
howevre it doe snot do anything n does not redirect either....

any ideas?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #6
this is what i have so far

catch
{
Response.Write("<script>window.alert('No Entries Found.Please
')</script>");
Response.Write("<script>window.document.location(' Menu.aspx')</script>")
;
}

so after i display the popup, i redirect it, is this the correct way? or
shud i use the script in the aspx page....if so how do i call it from
here(cs page)

Thanks for ur help
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #7
Ben

First of all, the javascript command is

window.document.location.href = "blah.aspx"

or, just

window.location.href = "blah.aspx"

You can also use

window.navigate("blah.aspx")

But some browsers (older IE, current IE/Mac and current Safari) don't like window.navigat

So, be careful

- - - - - - - - - - - - - -

Now, back to your original question about putting up a message box followed by the positioning on the date

Let's say you're getting the dates from GetDates.aspx and showing the grid on ShowActivity.aspx. In GetDates.aspx, the form's ID is OptionsForm, and the textbox you want to move to automatically is called FromDateTextBox

On ShowActivity.aspx, as soon as you know there's no activity, go back to GetDates.aspx with a parameter that flags for nothing found (be sure to do this before writing anything to the page; you'll get an error otherwise)

Response.Redirect("GetDates.aspx?NoActivity=Y", true)

Then, on GetDates.aspx, put the following

1. Alter your BODY tag so it looks like this
<body onload="OptionalNoActivityMessage();"

2. In the HEAD section, put something like this (this is ASP-ish rather than ASP.NET'ish, but I don't know a better way right now to get stuff into the HEAD section)
<head><script language="JavaScript"
function OptionalNoActivityMessage()
<
if (Request.QueryString["NoActivity"] != null && Request.QueryString["NoActivity"].Equals("Y"))
Response.Write("window.alert('Nothing found...');")
Response.Write("window.document.OptionsForm.FromDa teTextBox.focus();")

%
} // Closing brace for client-side function
</script></head

Here's the chain of events

1. User enters dates in GetDates.aspx, then submit
2. ShowActivity.aspx looks for activity, sees none, and redirects back to GetDates.aspx with a parameter that indicates nothing was found
3. In GetDates.aspx, because the "Not Found" parameter was set, the SERVER code inserts two CLIENT javascript commands that cause the browser to
3a. Show a messagebo
3b. Set the focus to the first date control after the user clears the messagebox

I hope this helps

Regards
Ed
Nov 18 '05 #8
Ed figured out the problem with your syntax. Use his.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Ben Arthur" <sk****@yahoo.com> wrote in message
news:#E*************@TK2MSFTNGP11.phx.gbl...
this is what i have so far

catch
{
Response.Write("<script>window.alert('No Entries Found.Please
')</script>");
Response.Write("<script>window.document.location(' Menu.aspx')</script>")
;
}

so after i display the popup, i redirect it, is this the correct way? or
shud i use the script in the aspx page....if so how do i call it from
here(cs page)

Thanks for ur help
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #9


Thanks for all ur detailed help Ed, it works......
Thanks again ! !
Ben

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Maziar Aflatoun | last post by:
Hi everyone, I'm writing an application that needs to quit when it encouters an error. However, Application.Exit() doesn't do anything here. Does anyone know why? public bool timerenabled {...
3
by: ZoombyWoof | last post by:
Hi. I'm pretty new to C# so this may seem like the dumbest question today, but I'm stuck. I have a small application, one Form that opens a connection to a database in its constructor. If the...
5
by: Jacek Jurkowski | last post by:
In a FMain of below application I'm throwing an Exception. It's catched by a catch section and application restarts. But in a reastarted application try section doesn't work no longer. Error...
4
by: Hari Koduru | last post by:
Hi All, I am getting the following exception in an ASP.NET application. Exception Details: System.InvalidOperationException: Application is restarting. I have been to the following Support...
2
by: Kevin Antel | last post by:
We've put the application in its own pool and turned off all recycling. Yet, when we get to a certain point in the application, we get kicked back to the beginning of the application and the event...
0
by: Kevin A | last post by:
The problem is that the web application mysteriously shuts down (ending all sessions) due to a supposed 'configuration change'. By using ASP.Net Health Monitoring we can determine that the...
2
by: Jeff | last post by:
I have a Asp.Net 1.1 application of which I have a very large datagrid on one of my pages. I am populating the datagrid by loading a xml file that is being stored in viewstate. After I have the...
2
by: Ian Boyd | last post by:
We're encountering a situation where we're encountering a deadlock, and someone's been made the deadlock victim. But after that, DB2 refuses to run any SQL, and instead we get the error message: ...
2
by: Jack | last post by:
Sorry for the double post (also in the IIS group). We've got an ASP.Net 2.0 app running on IIS6. We kept losing sessions, and enabled health monitoring to see what was happening. This morning...
1
by: =?Utf-8?B?RW1tYW51ZWwgVmVybHluZGU=?= | last post by:
Hi all, I have some troubles with my website build with combination of asp.net and asp pages. Sometimes, application pool restart and kill all my asp (classic) session variables. I see...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
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
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,...

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.