ラベル aspx の投稿を表示しています。 すべての投稿を表示
ラベル aspx の投稿を表示しています。 すべての投稿を表示

2012年3月28日水曜日

Response.redirect - display text in same page.

Hi guys,

I am using A.aspx , B.aspx and C.aspx pages.

From A.aspx I am calling b.aspx via Ajax code. After (Check Login user from database) success status , I am tryint o redirecting to C.aspx. But

C. aspx page content is dispalying in A.aspx. It suppose to be redirec to C.aspx. What I am dong wrong here..??

any suggessions ??

hello.

well, i'mo not following you. can you be more specific?


I am trying to check the Loginuser permissions from the Database. Once he get success permission the page has to redirect to new page.
here is my Code.

Login.aspx (a.aspx) - Enter user id & pwd and click Submit then below code executes


function CheckUser()
{
if (preLoginCheck())
{ var url = serverName+"checkLogUser.aspx?userID="+ document.frmDefault.txtUid.value +"&Pwd="+ document.frmDefault.txtPwd.value;
xmlHttp = GetXmlHttpObject(ChangeHandler);
xmlHttp_Get(xmlHttp, url);
}
}


function ChangeHandler()
{ if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete')
{ var getData=xmlHttp.responseText;
if (getData=="Success")
{ document.getElementById("ErrorCode").innerText=" GoooooooooooooooD";
}
else
{
document.getElementById("ErrorCode").innerText=getData; //" Invalid User name /Password";
}
}
}

checkLogUser.aspx (b.aspx) - Ajax will execute this page from here itself I want to redirec to Third Page..


If (tmpUserID <> "" And tmpUserPwd <> "") Then
crapObj = New CRAPManagement
getLogInStatus = crapObj.checkLoginUserAccess(tmpUserID, tmpUserPwd)
If getLogInStatus = "Success" Then
Response.Redirect("UserCreate.aspx") --> C.Aspx
Else
Response.Write(getLogInStatus)
End If
End If

Finanl result is C.Aspx page content is displaed in Login.aspx Page.


hello.

well, if you're using asp.net 2.0, then check the authenticationservice class:

http://www.asp.net/ajax/documentation/live/ClientReference/Sys.Services/AuthenticationServiceClass/default.aspx


Hello,
I could't understand wha should I do exactly...!


hello.

well, instead of writing your own code for making the remote call and then having to build your page on the server that has server logic for authenticating a user, you'll get that for free with the service i've showed you in the previous post (it'll authenticate by using forms authentication and it'll automatically use the current defined membership provider you've set up on the server side).

2012年3月26日月曜日

Response.Redirect in AJAX

I have a button in Update panel.

On button click I have written

Response.Redirect("InterMediateMsg.aspx", False)

When I executes the application I got the Error..

Sys.WebForms.PageRequestParserErrorException:The message received from the server could not be parsed.

How should I implement Redirection in AJAX.

Hi,

in the onclick (client side!!) you just place self.location.href='urltogoto'. Don't use AJAX for something like that but plain old javascript.

Grz, Kris.


Response.Redirect should work fine during an async postback. Try dropping the "False"... I'm not sure if you can use that option.


Actually I have performed server side coding( Database operations) on button click .

After the successful operation I want to navigate to another page.

How could I do it.


I have tried it by dropping false.

Actually this second parameter specifies whether I want to terminate execution of current page or not.

Is there any effect of browser.

I am using IE 6.0


Make sure that you have buffer set to false on the page from which you wish to redirect - otherwise output will already have been streamed out to the client, and things will go horribly wrong!

This cost me quite a bit of investigation a while ago..!


i think this error may be because it is trying to process a redirect within the update panel. assuming you use a trigger for the updatepanel and button, set it to a asp:PostBackTrigger instead of a asp:AsyncPostBackTrigger, this will send your page into a full postback, which may solve your problem (i haven't tested it).


I try the way you suggest, and its work !Wink


glad to help!Smile


Thnx ChrisCicc ,

It's working.

I have set the Trigger for button to PostBack and it worked.

ResponseFilter & Content-Encoding header, cleared by WriteExceptionJsonString

Hi There,

I have a ResponseFilter adding HTTP compression to my .aspx, ashx, and now .asmx requests, similar to http://blog.madskristensen.dk/post/HTTP-compression-in-ASPNET-20.aspx.

I've just starting using it to compress the web services in a project, which has worked great reducing the traffic immensely. To do this, I've added a response filter to the Response object, and set the "Content-Encoding" header to "gzip". Works great for normal pages and "MyService.asmx/js" requests as well.

Normally, when an exception is thrown inside a web service, the exception is serialised, passed along to the client, and handled by the error callback in javascript code. No worries there.

The error handling stopped working after added the compression as a response filter to the .asmx/js requests. It turns out that the method handles the error "WriteExceptionJsonString" found in "System.Web.Script.Services.RestHandler" clears the response headers before it serialises the exception. This isn't too bad in itself, but the response filter is still in place, so the gzip compression is still used, but now the client consuming the request doesn't know it needs decoding and a javascript error then occurs "result has no properties"

line 4860, result = new Sys.Net.WebServiceError(false, result.Message, result.StackTrace, result.ExceptionType);

Is there a way around this, while still allowing the compression? Or is this some kind behavioral bug in the underlying MS AJAX Rest handler? If theSystem.Web.Script.Services.RestHandler clears the headers... and the content... should it also remove any response filters?

I had a brain wave shortly after posting the previous message.

The HTTP Module I am using did all the Response.Filter setup in the PreRequestHandlerExecute event. That included the Response.AppendHeader("Content-Encoding", "gzip"). The header was subsequently cleared by the System.Web.Script.Services.RestHandler.WriteExceptionJsonString method, but the filter still compress the output stream.

So instead, I moved the Response.AppendHeader("Content-Encoding", "gzip") into the PreSendRequestHeaders event. Now the header gets set correctly for the Response.Filter GZipStream just before the headers are sent.

Hope that helps someone else.

2012年3月24日土曜日

Returning a datatable

Based on trying to return a DataSet, I have decided to try and justreturn a DataTable (fyi. http://forums.asp.net/1077805/ShowPost.aspx).
The problem is that in my javascript callback, I need to get at thedata that is returned. What methods are available on the returneddata? I have a datatable with several datarows, but I don't knowwhat methods are available to actually get at the data. BTW, I amtrying to do this programmatically and am not interested in adeclarative solution to this. When I attempt to alert out to theUI, result.length is coming through a undefined.
Web Service:
[WebMethod]
public System.Data.DataTable ReturnDataSet()
{
DataTable dt = new DataTable();
DataRow dr;
dt.Columns.Add(new DataColumn("tblStateId",System.Type.GetType("System.Int32")));
dt.Columns.Add(new DataColumn("State",System.Type.GetType("System.String")));
dr = dt.NewRow();
dr["tblStateId"] = 1;
dr["State"] = "Tennessee";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["tblStateId"] = 2;
dr["State"] = "Alabama";
dt.Rows.Add(dr);
return (dt);
}
Client Side Javascript:
function LoadTest(){
Samples.AspNet.WebServiceTest.ReturnDataSet(ReturnDataTableCallBack);
}

function ReturnDataTableCallBack(result)
{
var i = 0;
var ddl = document.getElementById("sState");
var optionItem;
iLength = document.getElementById("sState").options.length;
document.getElementById("sState").visible = true;
document.getElementById("txtAreaResult").value = result.get_data();
for(i=0; i<iLength; i++)
{
document.getElementById("sState").options[0] = null;
}

for(i=0; i<result.length; i++)
{
document.getElementById("sState").options.add(newOption(resultIdea [I]["State"],resultIdea [I]["tblStateId"]))
}
}


I think you should be able to write code like:
for (var i = 0; i < results.get_length(); i++) {
alert(results.getItem(i).State);
}
As a side note: there are several ways that you can use to 'discover'the structure of an object. One way is to usedebug.dump(object,name[,recursive[,indentationPadding]]), which shouldadd information about an object to the trace. Another way is to loopthrough the members of an object, like "for (m in myObject) alert(m);".

Great information. It got me on the right track. I foundthat the following pseudo-javascript was what was necessary:
for(i=0; i<result.get_length(); i++)
{
var optAdd = newOption(result.getItem(i).getProperty("State"),result.getItem(i).getProperty("tblStateId"));
document.getElementById("sState").options.add(optAdd);
}
The .State and .tblStateId properties did not return a value, but thegetProperty("State") and getProperty("tblStateId") did what wasnecessary.
Do you have a complete example of the debug.dump() method?
Wally

You could use "get_State()" instead of "getProperty('State')" too (which I think is nicer).
To use debug.dump, try something like "debug.dump(results, "my results", true)".

How would you do this declaratively? For example, if I wanted to bind the first state returned to a label...I've tried this, and it doesn't work:
<binding id="binding1" dataContext="dataSource1" dataPath="data[0].State" property="text" automatic="false" />
I can't figure out what to put in the dataPath. Anyone have some guidance?

Reuse AnimationExtenders

Hello!

I have a website where I want to put a kind of tooltips using animation extender. In each page (aspx file) there should be 4 tooltips, one in each textbox that the user has to fill.

They're gonna have the same estructure, i mean, one little button with the "?" sign, and when u click on it, the window with the info appears. For the 4 buttons, the animation code is the same (is the example of animation that appears in the AJAX Toolkit animation: resize and fade in a div with the information). The only thing it'll change is the target between the different animation extender. Is there any possibility to write only 2 animation extender(one to open the help and other to close it) for all of them, instead of one animation extender pair for each one?

In case is not possible, having so many extenders, can affect the speed of serving pages to the user?

Thanks a lot.

Oscar

yes

Hi,

thx for answering, but, "yes"? which question of them are u answering?


if possible to reuse the animation extender for several buttons? how please?

is gonna to slow the website if I put one for each button?


thx


Hi Oscar,

You can reuse an Animation Extender by providing its markup and changing the TargetControl before running it .

You can take a look at my post which talks about various ways to trigger the animations and how to use them to have a common schema for animations on a page.

http://blogs.msdn.com/phaniraj/archive/2007/04/13/animations-how-many-ways-do-i-call-thee.aspx

Hope this helps !!


Hi,

Firt of all, thx for answering (I've seen in different forums that u're quite active!). I am quite new using AJAX, so, is being difficult to me solving this problem. In ur post I've seen a method that can be easier for me. Instead of using the XML to define the actions, I'm gonna use a script that takes as params the targets of the actions.

So, my main problem now is to "translate" the XML I have to a function. I am having problems "translating" the <Parallel> tag. I hope u can help me with this:

<Parallel AnimationTarget="flyout" Duration=".3" Fps="25">
<Move Horizontal="150" Vertical="-50" />
<Resize Height="260" Width="280" />
<Color AnimationTarget="flyout" PropertyKey="backgroundColor"
StartValue="#AAAAAA" EndValue="#FFFFFF" />
</Parallel>

And this is what I've done:

function callStaticMethods(var_flyout){

var flyout = document.getElementById(var_flyout);

var par = new AjaxControlToolkit.Animation.ParallelAnimation();
par.add(new AjaxControlToolkit.Animation.ColorAnimation(flyout, 0.5, 25, 'style', 'backgroundColor', '#FFFFFF', '#AAAAAA'));
par.add(new AjaxControlToolkit.Animation.MoveAnimation(flyout, 0.3, 25, 500, 500, true, "px"));
par.add(new AjaxControlToolkit.Animation.ResizeAnimation(null, null, null, 260, 280, "px"));
par.play;

}

but nothing happens then.Do u know where is the problem??

Thx a lot!


Hi Oscar,
You got 90% of it rightSmile!!
The part that you missed is that when you use the script method of the animation
framework , you need to specify the targetControlId in the parent.

Please review the script method.

function callStaticMethods(var_flyout){

var flyout = $get(var_flyout);
var par = new AjaxControlToolkit.Animation.ParallelAnimation(flyOut, 0.3 , 25, null);
par.add( new AjaxControlToolkit.Animation.MoveAnimation(null, null, null, 150, -50,false, "px") );
par.add( new AjaxControlToolkit.Animation.ResizeAnimation(null, null, null, 280, 260, "px"));
par.add (new AjaxControlToolkit.Animation.ColorAnimation(null, null, null, "style" , "backgroundColor", "#AAAAAA", "#FFFFFF")
);
par.play()

}

On the other hand , if you have the Markup for the Animation on the page,
Conside the method "c) Selectively playing the Animation Already defined in Markup for an AnimationExtender on the Page."
described in my blog post for triggering the animation by changing the appropriate properties.

1) Assign a BehaviorId for your Animation Extender to be
<ajaxToolkit:AnimationExtender AnimationTargetScript="getCurrentElement()" BehaviorID ="parBehavior" ......>
<OnClick>
//ANimations Here.
</OnClick>
</ajaxToolkit:AnimationExtender
2)
//A Global Variable to Hold the Current Element to be animated.
var currentElement = ""
function getCurrentElement() {
return currentElement;
}
function callStaticMethods(var_flyout) {
currentElement = var_flyout;
//Get a handle to the Animation Behavior
var behaveYourself = $find("parBehavior");
//Get the Animation to be played onClick of the TargetControl
var onClickAnimation = behaveYourself.get_OnClickBehavior();
behaveYourself.play();
}

Hope this helps.
If this resolves your issue , please mark my reply as the answer.


Hi man!

First of all say that I'm feeling quiet stupid (well, i think "novice" is the word hehe) because you're giving me it so detailed and I still can′t make it works:

Problems:


a)The AnimationTargetScript in the AnimationExtender tag launchs an error and doesn′t allow me to execute (it says that is not a valid tag).

b) In ur example, I can′t see from where do u call the callStaticMethods function.

May be is useful if I explain a bit more what I want to do. In my animation extender there are 4 targets that should change by code depending wich button I play. Here is the code:

<asp:Button ID="btnInfo" runat="server" OnClientClick="return false;" Text="Click Here"/><!-- "Wire frame" div used to transition from the button to the info panel --> <div id="flyout" class="wireFrame"></div><!-- Info panel to be displayed as a flyout when the button is clicked --> <div id="info" style="display: none; width: 250px; z-index: 2; opacity: 0; filter: progid:DXImageTransform.Microsoft.Alpha(opacity=0); font-size: 12px; border: solid 1px #CCCCCC; background-color: #FFFFFF; padding: 5px;"> <div id="btnCloseParent" style="float: right; opacity: 100; filter: progid:DXImageTransform.Microsoft.Alpha(opacity=100);"> <asp:LinkButton id="btnClose" runat="server" OnClientClick="return false;" Text="X" ToolTip="Close" Style="background-color: #666666; color: #FFFFFF; text-align: center; font-weight: bold; text-decoration: none; border: outset thin #FFFFFF; padding: 5px;" /> </div> Once you get the general idea of the animation's markup, you'll want to play a bit. All of the animations are created from simple, reusable building blocks that you can compose together. Before long you'll be creating dazzling visuals. By grouping steps together and specifying them to be run either in sequence or in parallel, you'll achieve almost anything you can imagine, without writing a single line of code! </div> <script type="text/javascript" language="javascript"> // Move an element directly on top of another element (and optionally // make it the same size) function Cover(bottom, top, ignoreSize) { var location = Sys.UI.DomElement.getLocation(bottom); top.style.position = 'absolute'; top.style.top = location.y + 'px'; top.style.left = location.x + 'px'; if (!ignoreSize) { top.style.height = bottom.offsetHeight + 'px'; top.style.width = bottom.offsetWidth + 'px'; } } </script> <ajaxToolkit:AnimationExtender id="OpenAnimation" runat="server" TargetControlID="btnInfo"> <Animations> <OnClick> <Sequence> <%-- Disable the button so it can't be clicked again --%> <EnableAction Enabled="false" /> <%-- Position the wire frame and show it --%> <ScriptAction Script="Cover($get('btnInfo'), $get('flyout'));" /> <StyleAction AnimationTarget="flyout" Attribute="display" Value="block"/> <%-- Move the wire frame from the button's bounds to the info panel's bounds --%> <Parallel AnimationTarget="flyout" Duration=".3" Fps="25"> <Move Horizontal="150" Vertical="-50" /> <Resize Width="260" Height="280" /> <Color PropertyKey="backgroundColor" StartValue="#AAAAAA" EndValue="#FFFFFF" /> </Parallel> <%-- Move the panel on top of the wire frame, fade it in, and hide the frame --%> <ScriptAction Script="Cover($get('flyout'), $get('info'), true);" /> <StyleAction AnimationTarget="info" Attribute="display" Value="block"/> <FadeIn AnimationTarget="info" Duration=".2"/> <StyleAction AnimationTarget="flyout" Attribute="display" Value="none"/> </Sequence> </OnClick> </Animations> </ajaxToolkit:AnimationExtender> <ajaxToolkit:AnimationExtender id="CloseAnimation" runat="server" TargetControlID="btnClose"> <Animations> <OnClick> <Sequence AnimationTarget="info"> <%-- Shrink the panel out of view --%> <StyleAction Attribute="overflow" Value="hidden"/> <Parallel Duration=".3" Fps="15"> <Scale ScaleFactor="0.05" Center="true" ScaleFont="true" FontUnit="px" /> <FadeOut /> </Parallel> <%-- Reset the target --%> <StyleAction Attribute="display" Value="none"/> <StyleAction Attribute="width" Value="250px"/> <StyleAction Attribute="height" Value=""/> <StyleAction Attribute="fontSize" Value="12px"/> <%-- Enable the button --%> <EnableAction AnimationTarget="btnInfo" Enabled="true" /> </Sequence> </OnClick> </Animations> </ajaxToolkit:AnimationExtender>
This example work perfectly. The problem is that I'm gonna have 4 groups of the structure "flyout", "info", "btnOpen", "btnClose".

Man, thx a lot for ur help. I'd like to know a bit more and for sure it'd have been enough with ur blog example.

Anyway, I keep on trying.