Showing posts with label redirect. Show all posts
Showing posts with label redirect. Show all posts

Saturday, March 24, 2012

This ones going to be tricky

Hi

I need to pass a variable through a querystring in to another window, popup maybe.

Response.Redirect(

"~/Exam/ExamResult.aspx?sum=" + CalSum);

I thought about Target=_Blank but that will only work for links. Would i need javascript for this.

Any know of any solutions

not tricky, yes you do need javascript

in your HREF you put

thetargetpage.aspx?myName=valuePair.

then in the onClick event you use

window.open(this.href,ADDITIONAL WIDTH, HEIGHT, PARAMETERS)

should work pretty easily. the key is the javascript.onclikc takes its own href value which you can string your variables in.

hth,

mcm


You forgot one parameter :-D It's actually

window.open(URL, window name, additional params)

Cheers,


Cheers

But its not a href its a Resonse.Redirect written in C#

If that makes any sense

Code is order:

<

scriptrunat="server">void Button1_Click(object sender,EventArgs e)

{

int val1 = System.Convert.ToInt32(Q1.SelectedItem.Value);int val2 = System.Convert.ToInt32(Q2.SelectedItem.Value);int val3 = System.Convert.ToInt32(Q3.SelectedItem.Value);int val4 = System.Convert.ToInt32(Q4.SelectedItem.Value);int val5 = System.Convert.ToInt32(Q5.SelectedItem.Value);int val6 = System.Convert.ToInt32(Q6.SelectedItem.Value);int val7 = System.Convert.ToInt32(Q7.SelectedItem.Value);int val8 = System.Convert.ToInt32(Q8.SelectedItem.Value);int val9 = System.Convert.ToInt32(Q9.SelectedItem.Value);int val10 = System.Convert.ToInt32(Q10.SelectedItem.Value);int val11 = System.Convert.ToInt32(Q11.SelectedItem.Value);int val12 = System.Convert.ToInt32(Q12.SelectedItem.Value);int val13 = System.Convert.ToInt32(Q13.SelectedItem.Value);int val14 = System.Convert.ToInt32(Q14.SelectedItem.Value);int val15 = System.Convert.ToInt32(Q15.SelectedItem.Value);int val16 = System.Convert.ToInt32(Q16.SelectedItem.Value);int val17 = System.Convert.ToInt32(Q17.SelectedItem.Value);int val18 = System.Convert.ToInt32(Q18.SelectedItem.Value);int val19 = System.Convert.ToInt32(Q19.SelectedItem.Value);int val20 = System.Convert.ToInt32(Q20.SelectedItem.Value);int val21 = System.Convert.ToInt32(Q21.SelectedItem.Value);int val22 = System.Convert.ToInt32(Q22.SelectedItem.Value);int val23 = System.Convert.ToInt32(Q23.SelectedItem.Value);int val24 = System.Convert.ToInt32(Q24.SelectedItem.Value);int val25 = System.Convert.ToInt32(Q25.SelectedItem.Value);int CalSum = val1 + val2 + val3 + val4 + val5 + val6 + val7 + val8 + val9 + val10 + val11 + val12 + val13 + val14 + val15 + val16 + val17 + val18 + val19 + val20 + val21 + val22 + val23 + val24 + val25;

Label1.Text = CalSum.ToString();

Label2.Text = CalSum.ToString();

if (CalSum >= 1) {

Response.Redirect(

"~/Exam/ExamResult.aspx?sum=" + CalSum);

}

else {

Response.Redirect(

"~/Exam/ExamResult2.aspx");

}

}

</

script>As you can see i have button click event and and response.redirect and not a href with an OnClick event

Any ideas

Thanks in advance


Use this:

1if (CalSum >= 1)2 {3string _script ="<script>window.open('Exam/ExamResult.aspx?sum=" + CalSum.ToString() +"','popup','scrollbar=no menubar=no width=200 height=200');</script>";4 ClientScript.RegisterStartupScript(this.GetType(),"pop", _script);5 }6else7 {8string _script1 ="<script>window.open('Exam/ExamResult2.aspx','popup1','');</script>";9 ClientScript.RegisterStartupScript(this.GetType(),"pop1", _script1);10 }
Thanks

Right on, e_screw.

Ruckme, Response.Redirect works on the server, which has no knowledge of the browser (for things like new windows).

Cheers,


Wow theres some serious syntax in there, However it still doesnt work!

I am going to have dump all the script and say where the errors are:

script

runat="server">void Button1_Click(object sender,EventArgs e)

{

int val1 = System.Convert.ToInt32(Q1.SelectedItem.Value);int val2 = System.Convert.ToInt32(Q2.SelectedItem.Value);int val3 = System.Convert.ToInt32(Q3.SelectedItem.Value);int val4 = System.Convert.ToInt32(Q4.SelectedItem.Value);int val5 = System.Convert.ToInt32(Q5.SelectedItem.Value);int val6 = System.Convert.ToInt32(Q6.SelectedItem.Value);int val7 = System.Convert.ToInt32(Q7.SelectedItem.Value);int val8 = System.Convert.ToInt32(Q8.SelectedItem.Value);int val9 = System.Convert.ToInt32(Q9.SelectedItem.Value);int val10 = System.Convert.ToInt32(Q10.SelectedItem.Value);int val11 = System.Convert.ToInt32(Q11.SelectedItem.Value);int val12 = System.Convert.ToInt32(Q12.SelectedItem.Value);int val13 = System.Convert.ToInt32(Q13.SelectedItem.Value);int val14 = System.Convert.ToInt32(Q14.SelectedItem.Value);int val15 = System.Convert.ToInt32(Q15.SelectedItem.Value);int val16 = System.Convert.ToInt32(Q16.SelectedItem.Value);int val17 = System.Convert.ToInt32(Q17.SelectedItem.Value);int val18 = System.Convert.ToInt32(Q18.SelectedItem.Value);int val19 = System.Convert.ToInt32(Q19.SelectedItem.Value);int val20 = System.Convert.ToInt32(Q20.SelectedItem.Value);int val21 = System.Convert.ToInt32(Q21.SelectedItem.Value);int val22 = System.Convert.ToInt32(Q22.SelectedItem.Value);int val23 = System.Convert.ToInt32(Q23.SelectedItem.Value);int val24 = System.Convert.ToInt32(Q24.SelectedItem.Value);int val25 = System.Convert.ToInt32(Q25.SelectedItem.Value);int CalSum = val1 + val2 + val3 + val4 + val5 + val6 + val7 + val8 + val9 + val10 + val11 + val12 + val13 + val14 + val15 + val16 + val17 + val18 + val19 + val20 + val21 + val22 + val23 + val24 + val25;

Label1.Text = CalSum.ToString();

Label2.Text = CalSum.ToString();

if (CalSum >= 1)

{

string _script ="<script>window.open('Exam/ExamResult.aspx?sum=" + CalSum.ToString() +"','popup','scrollbar=no menubar=no width=200 height=200');</script>";

ClientScript.RegisterStartupScript(this.GetType(), "pop", _script);

}

else

{

string _script1 = "

<script>window.open('Exam/ExamResult2.aspx','popup1','');</script>";

ClientScript.RegisterStartupScript(this.GetType(), "pop1", _script1);

}

}

</

script>

Basically it says that there is a:CS1010: Newline in constant

on this line:

string _script ="<script>window.open('Exam/ExamResult.aspx?sum=" + CalSum.ToString() +"','popup','scrollbar=no menubar=no width=200 height=200');</script>";

Cheers i though this would be hard

Thans again


That is because you are writing the code in the aspx page (html) and with that are you trying to write <script> tag inside another <script> tag (your <script runat=server>). The code i provided is in code behind file.

Thanks


I thought it was because there was a newline in the string (after 'no'). However, since you're not using codebehind, you *will* want to change your string slightly as e_screw mentioned to avoid terminating the parent script early:

0');</scr" + "ipt>";

Also, I believe you should have commas instead of spaces between your list of formatting parameters:

string _script ="<script>window.open('Exam/ExamResult.aspx?sum=" + CalSum.ToString() +"','popup','scrollbar=no,menubar=no,width=200, height=200');</scr" + "ipt>";


Awsome it works!!!:):):

Thanks you very much everybody it works

Cheers

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

Tuesday, March 13, 2012

thread was being aborted

Hi, everyone

I create one application with form authentication.

When I try to run application and press login button it will redirect to default page and application run success fully, some time it will not redirect to default page .

For my application, I have to create one txt log file for error …

Sometime this error occurs when I press login button….

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

Source Code : mscorlib

Error Message : Thread was being aborted.

Stack Trace : at System.Threading.Thread.AbortInternal()

at System.Threading.Thread.Abort()

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 pms._default.Page_Load(Object sender, EventArgs e) in C:\Inetpub\wwwroot\aspnet\pms\default.aspx.vb:line 104

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

source code for login button is……

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

Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click

Try

singleSqlString = "SELECT emp_code,password,access_level,emp_name " & _

"FROM login_master " & _

"WHERE emp_code='" & txtEmpCode.Text & "' AND password='" & txtPassword.Text & "' " & _

"ORDER BY emp_code ASC"

objlogin.FillDataSet(singleSqlString, "login_master")

If objlogin.dtSet.Tables("login_master").Rows.Count > 0 Then

Session("LoginCode") = txtEmpCode.Text

Session("EmpName") = objlogin.dtSet.Tables("login_master").Rows(0).Item("emp_name")

Session("AccessLevel") = objlogin.dtSet.Tables("login_master").Rows(0).Item("access_level")

FormsAuthentication.RedirectFromLoginPage(txtEmpCode.Text, False)

Else

lblmsg.Text = " Employee Code or Password may be wrong. - Try Again !!"

txtEmpCode.Text = ""

txtPassword.Text = ""

End If

Catch ex As ThreadAbortException

lblmsg.Visible = True

lblmsg.Text = "Thread is aboard"

Catch ex As Exception

objlogin.CreateLogFile(ex, objlogin.Message)

End Try

End Sub

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

when I trace my application using break point exception is not generated , but error occurs

plz give any solution and cause for this error.

Thanks in advance

Hi,

The error generated appears to be occuring on the default page:

at pms._default.Page_Load(Object sender, EventArgs e) in C:\Inetpub\wwwroot\aspnet\pms\default.aspx.vb:line 104

Have you checked/debugged the code here to see what's happening?

Thread was being aborted

Hi,

I have an ASPX page that does a Response.Redirect.

I get a message stating "Thread was being aborted".

The page I am redirecting to only have 2 lines of VB.

Anyone know why I am getting this error?

Thanks,
C.You may try "Response.Redirect ("aspxName.aspx",false)".

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.
>

Thread was being aborted in Response.Redirect

I am logging the following error when re-directing via Response.Redirect:
"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 ..."
It doesn't interfere with the functionality and is transparent, and the only
reason I know it is tripped is because I write the errors to a log.
I am doing some processing in my code-behind, and after processing simply
re-direct to the next page. Is there a proper way of ending things before
re-directing?
I have used the boolean parameter for ending the thread, but it seems to
have no effect.
Thanks,
gsk
http://www.meblogic.comthis is normal, Response.End() is implemented as a thread abort.
-- bruce (sqlwork.com)
"GSK" <gsk@.NiOcSaP.nAeMt> wrote in message
news:uAXMCCYTEHA.1168@.TK2MSFTNGP11.phx.gbl...
> I am logging the following error when re-directing via Response.Redirect:
> "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 ..."
> It doesn't interfere with the functionality and is transparent, and the
only
> reason I know it is tripped is because I write the errors to a log.
> I am doing some processing in my code-behind, and after processing simply
> re-direct to the next page. Is there a proper way of ending things before
> re-directing?
> I have used the boolean parameter for ending the thread, but it seems to
> have no effect.
> Thanks,
> gsk
> http://www.meblogic.com
>
>