When we want to confirm a user action before a post back occurs, we've been
writing code like this:
function onClickDelete()
{
var aResponse = window.confirm("Delete this record?");
if ( aResponse )
__doPostBack('theLayout$_ctl1$buttonDelete','') ;
return 0;
}
This seems like an "un-natural" act - is there a better way?
-- dwathe OOP approach would be to subclass the button, and add a confim property,
that can be set in the designer, or in the code behind. the new control
would then handle rendering the required javascript.
-- bruce (sqlwork.com)
"dwa" <da@.hotmail.com> wrote in message
news:O$CrRbe5DHA.2696@.TK2MSFTNGP09.phx.gbl...
> When we want to confirm a user action before a post back occurs, we've
been
> writing code like this:
> function onClickDelete()
> {
> var aResponse = window.confirm("Delete this record?");
> if ( aResponse )
> __doPostBack('theLayout$_ctl1$buttonDelete','') ;
> return 0;
> }
> This seems like an "un-natural" act - is there a better way?
> -- dwa
"bruce barker" <nospam_brubar@.safeco.com> wrote in message
news:%23bSpRse5DHA.1428@.TK2MSFTNGP12.phx.gbl...
> the OOP approach would be to subclass the button, and add a confim
property,
> that can be set in the designer, or in the code behind. the new control
> would then handle rendering the required javascript.
Yes. OOP as in: "Oooooops! This took a lot longer to complete than it
should have (2 hours as opposed to 2 minutes), and now we've got another
component to unit test..."
<ggg
There ought to be a 5 *second* approach to solve such a problem. It's
throw-away.
-- dwa
You can do this from code to the button, i'm not quite sure yet how you can
set onClick attributes to a web control from the designer.
Button1.Attributes.Add("onClick", "javascript:return confirm('are you
sure');")
"dwa" <da@.hotmail.com> wrote in message
news:O$CrRbe5DHA.2696@.TK2MSFTNGP09.phx.gbl...
> When we want to confirm a user action before a post back occurs, we've
been
> writing code like this:
> function onClickDelete()
> {
> var aResponse = window.confirm("Delete this record?");
> if ( aResponse )
> __doPostBack('theLayout$_ctl1$buttonDelete','') ;
> return 0;
> }
> This seems like an "un-natural" act - is there a better way?
> -- dwa
If the button is called btn1, add the following code to the Page_load: (in
vb)
Dim btn as button = btn1
btn.Attributes.Add("onClick")="javascript: return etc. ..."
The code in the onclick event of the button will only fire when the
javascript returns TRUE.
"Michael Ramey" <raterus@.localhost> schreef in bericht
news:Ov7pjye5DHA.2416@.TK2MSFTNGP10.phx.gbl...
> You can do this from code to the button, i'm not quite sure yet how you
can
> set onClick attributes to a web control from the designer.
> Button1.Attributes.Add("onClick", "javascript:return confirm('are you
> sure');")
> "dwa" <da@.hotmail.com> wrote in message
> news:O$CrRbe5DHA.2696@.TK2MSFTNGP09.phx.gbl...
> > When we want to confirm a user action before a post back occurs, we've
> been
> > writing code like this:
> > function onClickDelete()
> > {
> > var aResponse = window.confirm("Delete this record?");
> > if ( aResponse )
> > __doPostBack('theLayout$_ctl1$buttonDelete','') ;
> > return 0;
> > }
> > This seems like an "un-natural" act - is there a better way?
> > -- dwa
Problem with doing this sort of client side rerouting is that.. sometimes
the client has script accessed turned off, using a low level browser, etc.
etc. all sorts of problems. Therefore I decided to just make a simple server
sideded dialog box... STILL an ugly hack though. =P
"Martin" <anolis@.mail2world.com> wrote in message
news:40183939$0$89909$1b2cd167@.news.wanadoo.nl...
> If the button is called btn1, add the following code to the Page_load: (in
> vb)
> Dim btn as button = btn1
> btn.Attributes.Add("onClick")="javascript: return etc. ..."
> The code in the onclick event of the button will only fire when the
> javascript returns TRUE.
>
> "Michael Ramey" <raterus@.localhost> schreef in bericht
> news:Ov7pjye5DHA.2416@.TK2MSFTNGP10.phx.gbl...
> > You can do this from code to the button, i'm not quite sure yet how you
> can
> > set onClick attributes to a web control from the designer.
> > Button1.Attributes.Add("onClick", "javascript:return confirm('are you
> > sure');")
> > "dwa" <da@.hotmail.com> wrote in message
> > news:O$CrRbe5DHA.2696@.TK2MSFTNGP09.phx.gbl...
> > > When we want to confirm a user action before a post back occurs,
we've
> > been
> > > writing code like this:
> > > > function onClickDelete()
> > > {
> > > var aResponse = window.confirm("Delete this record?");
> > > if ( aResponse )
> > > __doPostBack('theLayout$_ctl1$buttonDelete','') ;
> > > return 0;
> > > }
> > > > This seems like an "un-natural" act - is there a better way?
> > > > -- dwa
> > >
Showing posts with label aresponse. Show all posts
Showing posts with label aresponse. Show all posts
Saturday, March 31, 2012
There MUST be a better way!
Labels:
action,
aresponse,
asp,
back,
beenwriting,
code,
confirm,
net,
occurs,
onclickdelete,
thisfunction,
user,
var
Thursday, March 22, 2012
Thread Error
I get this thread error in my custom error log. It occurs on a
Response.Redirect statement. The odd thing it does not seem to affect
the functionality of the application at all. What causes this error:
System.Threading.ThreadAbortException: Thread was being aborted.
at System.Threading.Thread.AbortInternal()
at System.Threading.Thread.Abort(Object stateInfo)
at System.Web.HttpResponse.End()
at System.Web.HttpResponse.Redirect(String url, Boolean endResponse)
at System.Web.HttpResponse.Redirect(String url)
at contact911.planpayment.ProcessOrder() in C:\Inetpub\wwwroot\dirname\payment.aspx.vb:line 344.net pages run as programs, since you redirected the user, the program stops running.
This doesn't always happen though, its actually rare (it happens on two of my pages out of about 50). Why would the page still be running when the redirect occurs?
well it's not that the others r still running, just that exception while closing them wasnt thrown, lookig at it again, it seems like the error is when the thread tries to abort, but is already aborting.. perhaps something to do wih how quickly things are executed.
there is likely nothing you can do about it though, the exception comes from within the redirect statement, not your code.
The other possibility i can think of is perhaps if you have code in the unload event of those two forms.. but the strack trace indicates that it comes from the redirect statement.. so i guess that possibility is out.
I'm not that concern that the error is thrown, I'm just worried if the functionality will be interrupted. There is a lot of code in the Submit_Click method, then a lot of code in the Page_Load method of the page it goes too - maybe thats why it doesn't finish smoothly? So far all the functionality executes properly and completely, even when the error is thrown, but I'd still like to know why its doing it.
I did alot of searching, and it seems this is normal behavior.. all the typical asp ending functions will throw an exception most of the time.. which has to be a design flaw on microsofts behalf..
the way to fix it, tells microsoft is using the overload .Redirect("url", False)
and instead of response.end (for future reference) use HttpContext.Current.ApplicationInstance.CompleteRequest
i found this info at http://support.microsoft.com/default.aspx?scid=KB;EN-US;312629
Response.Redirect statement. The odd thing it does not seem to affect
the functionality of the application at all. What causes this error:
System.Threading.ThreadAbortException: Thread was being aborted.
at System.Threading.Thread.AbortInternal()
at System.Threading.Thread.Abort(Object stateInfo)
at System.Web.HttpResponse.End()
at System.Web.HttpResponse.Redirect(String url, Boolean endResponse)
at System.Web.HttpResponse.Redirect(String url)
at contact911.planpayment.ProcessOrder() in C:\Inetpub\wwwroot\dirname\payment.aspx.vb:line 344.net pages run as programs, since you redirected the user, the program stops running.
This doesn't always happen though, its actually rare (it happens on two of my pages out of about 50). Why would the page still be running when the redirect occurs?
well it's not that the others r still running, just that exception while closing them wasnt thrown, lookig at it again, it seems like the error is when the thread tries to abort, but is already aborting.. perhaps something to do wih how quickly things are executed.
there is likely nothing you can do about it though, the exception comes from within the redirect statement, not your code.
The other possibility i can think of is perhaps if you have code in the unload event of those two forms.. but the strack trace indicates that it comes from the redirect statement.. so i guess that possibility is out.
I'm not that concern that the error is thrown, I'm just worried if the functionality will be interrupted. There is a lot of code in the Submit_Click method, then a lot of code in the Page_Load method of the page it goes too - maybe thats why it doesn't finish smoothly? So far all the functionality executes properly and completely, even when the error is thrown, but I'd still like to know why its doing it.
I did alot of searching, and it seems this is normal behavior.. all the typical asp ending functions will throw an exception most of the time.. which has to be a design flaw on microsofts behalf..
the way to fix it, tells microsoft is using the overload .Redirect("url", False)
and instead of response.end (for future reference) use HttpContext.Current.ApplicationInstance.CompleteRequest
i found this info at http://support.microsoft.com/default.aspx?scid=KB;EN-US;312629
Tuesday, March 13, 2012
Thread was being aborted
Hi,
I have a login page, and after i validate a username and password i use a
response.redirect to the default page. The username and password are stored
in an sql db. In the response.redirect i use some session variables to be
added in the query string. However i am getting a "Thread was being
aborted.". Any ideas why this could happen?
Thanks inadvance.hi
You should not include the code "Response.redirect.. " in the code blok
"Try {} catch{}"
Sample:
try
{
//deal with the login logic
}
catch(Exception e)
{
}
Response.redirect("default.aspx");
Thanks a lot, it worked. But out of curiosity, you know why the error was
raised' what goes through the try-catch block that raised that error?
"Solo" <sunsolo@.gmail.com> wrote in message
news:1125819246.425176.236590@.z14g2000cwz.googlegroups.com...
> hi
> You should not include the code "Response.redirect.. " in the code blok
> "Try {} catch{}"
> Sample:
> try
> {
> //deal with the login logic
> }
> catch(Exception e)
> {
> }
> Response.redirect("default.aspx");
>
"Loui Mercieca" <loui@.destiny-creations.com> wrote in message
news:%23p3c7USsFHA.1132@.TK2MSFTNGP10.phx.gbl...
> Thanks a lot, it worked. But out of curiosity, you know why the error was
> raised' what goes through the try-catch block that raised that error?
It's a fairly common "gotcha". If you'd written:
Response.Redirect("default.aspx", false);
you wouldn't have got the error...
Loui,
this is what happens:
"The Response.End method ends the page execution and shifts the execution to
the Application_EndRequest event in the application's event pipeline. The
line of code that follows Response.End is not executed.
This problem occurs in the Response.Redirect and Server.Transfer methods
because both methods call Response.End internally. "
This behavior is by design. You can read about it in
http://support.microsoft.com/default.aspx?scid=kb;[LN];312629
Does this information help you?
Daniel Walzenbach
"Loui Mercieca" <loui@.destiny-creations.com> schrieb im Newsbeitrag
news:OvrjmBSsFHA.3504@.TK2MSFTNGP10.phx.gbl...
> Hi,
> I have a login page, and after i validate a username and password i use a
> response.redirect to the default page. The username and password are
> stored in an sql db. In the response.redirect i use some session variables
> to be added in the query string. However i am getting a "Thread was being
> aborted.". Any ideas why this could happen?
> Thanks inadvance.
>
I have a login page, and after i validate a username and password i use a
response.redirect to the default page. The username and password are stored
in an sql db. In the response.redirect i use some session variables to be
added in the query string. However i am getting a "Thread was being
aborted.". Any ideas why this could happen?
Thanks inadvance.hi
You should not include the code "Response.redirect.. " in the code blok
"Try {} catch{}"
Sample:
try
{
//deal with the login logic
}
catch(Exception e)
{
}
Response.redirect("default.aspx");
Thanks a lot, it worked. But out of curiosity, you know why the error was
raised' what goes through the try-catch block that raised that error?
"Solo" <sunsolo@.gmail.com> wrote in message
news:1125819246.425176.236590@.z14g2000cwz.googlegroups.com...
> hi
> You should not include the code "Response.redirect.. " in the code blok
> "Try {} catch{}"
> Sample:
> try
> {
> //deal with the login logic
> }
> catch(Exception e)
> {
> }
> Response.redirect("default.aspx");
>
"Loui Mercieca" <loui@.destiny-creations.com> wrote in message
news:%23p3c7USsFHA.1132@.TK2MSFTNGP10.phx.gbl...
> Thanks a lot, it worked. But out of curiosity, you know why the error was
> raised' what goes through the try-catch block that raised that error?
It's a fairly common "gotcha". If you'd written:
Response.Redirect("default.aspx", false);
you wouldn't have got the error...
Loui,
this is what happens:
"The Response.End method ends the page execution and shifts the execution to
the Application_EndRequest event in the application's event pipeline. The
line of code that follows Response.End is not executed.
This problem occurs in the Response.Redirect and Server.Transfer methods
because both methods call Response.End internally. "
This behavior is by design. You can read about it in
http://support.microsoft.com/default.aspx?scid=kb;[LN];312629
Does this information help you?
Daniel Walzenbach
"Loui Mercieca" <loui@.destiny-creations.com> schrieb im Newsbeitrag
news:OvrjmBSsFHA.3504@.TK2MSFTNGP10.phx.gbl...
> Hi,
> I have a login page, and after i validate a username and password i use a
> response.redirect to the default page. The username and password are
> stored in an sql db. In the response.redirect i use some session variables
> to be added in the query string. However i am getting a "Thread was being
> aborted.". Any ideas why this could happen?
> Thanks inadvance.
>
Subscribe to:
Posts (Atom)