Showing posts with label response. Show all posts
Showing posts with label response. 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 & timer in Web application C#

Hi all,I am using web application to request some infomation to the validgateway and get the response. But in some time if we request theinvalid gateway it wont response. So the application does not doanything without the response. So I planned to use the thread and timerconcept. If I put the function in thread and used the timer concept. Inthe windows application i did the same using the thread and the timertick. I dont know how to implement in the web application. If anybodyknows please give me ur suggestions.

Hi,

You might get some idea from here,

http://ajax.asp.net/docs/overview/UsingTimerControlTutorial.aspxhttp://www.codeplex.com/AtlasControlToolkit/Release/ProjectReleases.aspx?ReleaseId=1813http://www.codeproject.com/Ajax/stoppabletimer.asphttp://www.codeproject.com/useritems/WebTimer.asp http://www.codeproject.com/aspnet/dhtml_timer.asp


use ajax....

<script>

var xmlHttp

function showHint()

{

//var url="concession/AJAX_Code.aspx"

var url="timeservice.asmx/HelloWorld"

xmlHttp=GetXmlHttpObject(stateChanged)

xmlHttp.open("post", url ,true)

xmlHttp.send(null)

window.setTimeout("showHint()",1000);

}

function stateChanged()

{

if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")

{

document.getElementById("lblDate").innerHTML=xmlHttp.responseText

}

}

function GetXmlHttpObject(handler)

{

var objXmlHttp=null

if (navigator.userAgent.indexOf("Opera")>=0)

{

alert("This example doesn't work in Opera")return

}

if (navigator.userAgent.indexOf("MSIE")>=0)

{

var strName="Msxml2.XMLHTTP"

if (navigator.appVersion.indexOf("MSIE 5.5")>=0)

{

strName="Microsoft.XMLHTTP"

}

try

{

objXmlHttp=new ActiveXObject(strName)

objXmlHttp.onreadystatechange=handler

return objXmlHttp

}

catch(e)

{

alert("Error. Scripting for ActiveX might be disabled")return

}

}

if (navigator.userAgent.indexOf("Mozilla")>=0)

{

objXmlHttp=new XMLHttpRequest()

objXmlHttp.onload=handler

objXmlHttp.onerror=handler

return objXmlHttp

}

}

</script>

//////////////And the webservice for this is

<WebMethod()> _

PublicFunction HelloWorld()AsString

Return Now.ToString("dd-MMMM-yyyy hh:mm:ss")

EndFunction

Thread aborted when doing HttpContext.Current.Response.End

Hi,
I have written a function to export the datagrid data to excel. In that
function I was calling HttpContext.Current.Response.End() at the end. If I a
m
doing this, I am getting an exception message "Thread was being aborted". If
I don't do this then it is exporting the whole data instead of just the
datagrid. I am not knowing what might be the problem. Please let me know if
you have any idea
Thnx,
Sridhar.That's just how Response.End() works, it throws a ThreadAbortExxception.
You can't doing anything wrong, but you may. You'll either need to handle
(catch/swallow/hide) the exception or change your page so only the grid
shows and there's no need to End the request.
Karl
MY ASP.Net tutorials
http://www.openmymind.net/
http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!
"Sridhar" <Sridhar@.discussions.microsoft.com> wrote in message
news:92D1C4A0-006D-4DB7-87D3-86E26C8D0FD9@.microsoft.com...
> Hi,
> I have written a function to export the datagrid data to excel. In that
> function I was calling HttpContext.Current.Response.End() at the end. If I
> am
> doing this, I am getting an exception message "Thread was being aborted".
> If
> I don't do this then it is exporting the whole data instead of just the
> datagrid. I am not knowing what might be the problem. Please let me know
> if
> you have any idea
> Thnx,
> Sridhar.

Thread aborted when doing HttpContext.Current.Response.End

Hi,

I have written a function to export the datagrid data to excel. In that
function I was calling HttpContext.Current.Response.End() at the end. If I am
doing this, I am getting an exception message "Thread was being aborted". If
I don't do this then it is exporting the whole data instead of just the
datagrid. I am not knowing what might be the problem. Please let me know if
you have any idea

Thnx,
Sridhar.That's just how Response.End() works, it throws a ThreadAbortExxception.
You can't doing anything wrong, but you may. You'll either need to handle
(catch/swallow/hide) the exception or change your page so only the grid
shows and there's no need to End the request.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!

"Sridhar" <Sridhar@.discussions.microsoft.com> wrote in message
news:92D1C4A0-006D-4DB7-87D3-86E26C8D0FD9@.microsoft.com...
> Hi,
> I have written a function to export the datagrid data to excel. In that
> function I was calling HttpContext.Current.Response.End() at the end. If I
> am
> doing this, I am getting an exception message "Thread was being aborted".
> If
> I don't do this then it is exporting the whole data instead of just the
> datagrid. I am not knowing what might be the problem. Please let me know
> if
> you have any idea
> Thnx,
> Sridhar.

Tuesday, March 13, 2012

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