Showing posts with label server. Show all posts
Showing posts with label server. Show all posts

Wednesday, March 28, 2012

Trace AJAX webpage

I tried to trace AJAX enabled webpage and got the error:Sys.WebForms.PageRequestManagerParseErrorException. The message received from the server can not be parsed.

Any idea about that?

You can't use trace with Ajax. Trace kind of intercepts the page and reformats it so it can append the trace data. You'll have to try playing around with the debug functions that are part of Ajax Beta 1 and 2...


It should be possible to use tracing with MS AJAX. Just don't use in-page tracing. Set pageOutput to false, and look at the Trace.axd page.

Additional detailshere.


Thank you, muslon. It works.

Trapping server errors

If an asynchronous call generates an error on the server side, the client displays a Javascript alert box with the basic error message, for instance "Object reference not set to an instance of an object".

Is there any mechanism to trap and react to these errors on the client side, for instance directing them to an error page instead of showing them the alert box?

Mike

You can set in web.config

<customErrors mode="RemoteOnly" defaultRedirect="GenericError.aspx">
</customErrors>

So that client side will be rredirected to GenericError.aspx instead of getting an error...


I think you misunderstand the question. These are server side errors that occur on an AJAX asynchronous postback, rather than a regular postback, so it is not possible to redirect the client by using either the built in ASP.NET custom error page functionality, or by using Response.Redirect.

There must be some mechanism within the AJAX library for me to specify what to do in the case of an exception being raised. Really, all I want to do is, instead of the alert box showing the .NET error message, it should show something generic like "Oops, an error occured".

Can someone tell me how I do this?

Mike


Check this example, might be useful for you .

http://ajax.asp.net/docs/ViewSample.aspx?sref=Sys.Net.ErrorHandlingTutorial%23WebServiceMethodError.aspx

http://ajax.asp.net/docs/tutorials/ConsumingWebServicesWithAJAXTutorial.aspx

Treeview & UpdatePanel - Assertion failed - cant find last / in base url

Hi,

I am using a TreeView and couple of server controls. The treeview children are dynamically added on click of a node. I have the treeview control inside an update panel. Everything works if I access the page in a normal IE window. When I try to access the same page through a modal dialog, during postback, it opens a new window. To avoid that, I've added<base target = "_self" />.

Now I'm getting another error with Atlas. On click of tree node, it says "Assertion Failed : Can't find last / in base url. If I remove the <base..> it doesn't work.

Looking for an immediate solution. I've spent almost a day in googling. But no luck yet.

Many Thanks,
Mani.

hello.

you can also try using an iframe inside your popup page (ie, put only an iframe inside your popoup window which loads the page that shows the content)...maybe it'll solve that problem.


Mani,

Add:<basetarget="_self"href="http://localhost/***/***/"runat="server"/>

because our dear js function check if u have base tag , then try to concat with href value. in your case you don't have it.

T.


what if i'm using a Master Page - i can't hard code a path in the href. Is there any way to accomplish this? Plus - even if i hard code, the paging on my grid view does not work now.

trans642:

Mani,

Add:<basetarget="_self"href="http://localhost/***/***/"runat="server"/>

because our dear js function check if u have base tag , then try to concat with href value. in your case you don't have it.

T.

GOOD THANKS !


trans642:

Mani,

Add:<basetarget="_self"href="http://localhost/***/***/"runat="server"/>

because our dear js function check if u have base tag , then try to concat with href value. in your case you don't have it.

T.

GOOD THANKS !


Try this, without hard code urlSmile
 <base target="_self" href="<%=Request.Url.OriginalString%>" />

works perfect ... Thanks.

TreeView and UpdatePanel

I create a web form to display directory structure of the disks of the server. I put a treeview on the form and fill it with the drive and directory names. Everything was fine until I put a UpdatePanel (and ScriptManager ofcourse) on the form and move the TreeView into it. Now, I have a problem with the first node of the treeview (C:\). When I expand that node I see all the directories in the root of the C: drive. But when I expand any directory, all the nodes collapses. Than, other root nodes (D:, E: etc) works properly, but C: is not. What is the thing I miss? I use Visual Studio 2005 and AJAX January CTP. My code is as follows;

protectedvoid Page_Load(object sender,EventArgs e)

{

string[] drives;int i;TreeNode node, initialChildNode;DriveInfo driveInfo;if (!Page.IsPostBack)

{

tvFileSystem.Nodes.Clear();

drives =

Environment.GetLogicalDrives();for (i = 0; i < drives.Length; i++)

{

node =

newTreeNode();

driveInfo =

newDriveInfo(drives[i]);try

{

node.Text = driveInfo.VolumeLabel +

"(" + drives[i] +")";

}

catch

{

node.Text = driveInfo.DriveType +

"(" + drives[i] +")";

}

node.Value = drives[i];

initialChildNode =

newTreeNode();

initialChildNode.Text =

".";

initialChildNode.Value =

".";

node.ChildNodes.Add(initialChildNode);

tvFileSystem.Nodes.Add(node);

node.Collapse();

}

tvFileSystem.CollapseAll();

}

}

protectedvoid tvFileSystem_TreeNodeExpanded(object sender,TreeNodeEventArgs e)

{

TreeNode node = e.Node;TreeNode initialChildNode, newNode, tempNode;DirectoryInfo dirInfo;DirectoryInfo[] subDirInfo;string path ="";string[] subDirs;int i;string dirName, js;if (node.Value ==".")return;

tempNode = node;

while (tempNode !=null)

{

path = tempNode.Value +

"\\" + path;

tempNode = tempNode.Parent;

}

try

{

dirInfo =

newDirectoryInfo(path);

subDirInfo = dirInfo.GetDirectories();

}

catch (Exception e1)

{

js =

"<script>alert('" + e1.Message.Replace("\r","").Replace("\n","") +"');</script>";

Page.ClientScript.RegisterStartupScript(

typeof(string),"expandError", js);return;

}

node.ChildNodes.Clear();

for (i = 0; i < subDirInfo.Length; i++)

{

newNode =

newTreeNode();

dirName = subDirInfo[i].Name;

newNode.Text = dirName;

newNode.Value = dirName;

try

{

subDirs =

Directory.GetDirectories(subDirInfo[i].FullName);if (subDirs.Length > 0)

{

initialChildNode =

newTreeNode();

initialChildNode.Text =

".";

initialChildNode.Value =

".";

newNode.ChildNodes.Add(initialChildNode);

}

node.ChildNodes.Add(newNode);

}

catch { };

}

}

And the aspx file :

<%

@dotnet.itags.org.PageLanguage="C#"AutoEventWireup="true"CodeFile="dirTree.aspx.cs"Inherits="dirTree" %>

<!

DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<

htmlxmlns="http://www.w3.org/1999/xhtml">

<

headrunat="server"><title>Untitled Page</title>

</

head>

<

body><formid="form1"runat="server"><div><asp:ScriptManagerID="ScriptManager1"runat="server"></asp:ScriptManager>

</div><asp:UpdatePanelID="UpdatePanel1"runat="server"><ContentTemplate> <asp:TreeViewID="tvFileSystem"runat="server"OnTreeNodeExpanded="tvFileSystem_TreeNodeExpanded"Style="position: static"><SelectedNodeStyleBackColor="NavajoWhite"/><NodeStyleForeColor="Black"/></asp:TreeView></ContentTemplate></asp:UpdatePanel></form>

</

body>

</

html>

From what I have read, Treeviews and Menus do not work inside UpdatePanels. I did, however, get the menu to work without posting back by keeping the menu out of the UpdatePanel, but calling the appropriate menu event from the updatepanel.

<asp:UpdatePanel runat="Server" id="upSomeUpdatePanel" UpdateMode="Conditional">
<contentTemplate>
</contentTemplate>
<Triggers>
<AutoSyncPostBackTrigger ControlID="TreeViewID" Event="treevieweventname" />
</triggers>
</asp:UpdatePanel>

Don't copy and paste my code above because I did it all by memory and some of the control parameters might have slightly different names, but I hope you get the drift. The "treevieweventname" would be the name of the event you want to do without posting back - like "TreeNodeExpanded".

Hope this helps.


I have a treeview that works fine inside of an update panel.


What I'm doing differently is I'm not using the Expanded event,I'm using the TreeNodePopulate event and setting each node thathas children's "PopulateOnDemand" property to true. MyTreeView is inside an update panel and it expands, collapses,dynamically populates, etc. just fine.


By the way, I created a thread in this forum with a working example of a TreeView in an update panel using the technique I mentioned. I used the FileSystem since it's easy and doesn't requrie a database, it isn't exactly like yours but it works. It should show up soon upon moderation. Let me know if that helps!


Thank you aaron,

Your example is very helpful for me. But, what if I want user to select a node. I need to hold the selected node value, for example in a HiddenField. I modified your example by removing "Selected.Action = TreeNodeSelectAction.None" lines. And I add SelectedNodeChanged Event which includes following code:

hdSelectedPath.Value = tvFiles.SelectedNode.Value;

Now, it works except some thing. If I selects a node, then expands another node and select another node, the selected nodes changes in a wrong way. I mean, any other node is selected which I did not select.

What is the point I miss?

Thanks.


Thank you aaron,

Your example is very helpful for me. But, what if I want user to select a node. I need to hold the selected node value, for example in a HiddenField. I modified your example by removing "Selected.Action = TreeNodeSelectAction.None" lines. And I add SelectedNodeChanged Event which includes following code:

hdSelectedPath.Value = tvFiles.SelectedNode.Value;

Now, it works except some thing. If I selects a node, then expands another node and select another node, the selected nodes changes in a wrong way. I mean, any other node is selected which I did not select.

What is the point I miss?

Thanks.

Monday, March 26, 2012

Trigger full postback from the server during a partial postback.

Well, I have a dialog user control (ajax popup) which can again contain other user asp user controls as content. The content of the dialog is created inside an UpdatePanel, so that the dialog content can postback. All of that works OK.

On the web page I have now some information visible inside a GridView which is not in an UpdatePanel and should not be, because I need the browser forward/backward button to work. A link on that web page lets one of these dialog controls pop up. The dialog contains a user control which can manipulate the data which is visible inside the GridView. If the user presses a button inside the dialog, the dialog does an asynchronous postback as the user control/dialog content is inside an update panel and the dialog closes. That gives the user the impression that nothing happened as the data visible in the GridView did not change. I do already have the code to refresh the gridview, but how can I change the behavior during the postback from being an asynchronous postback to a full postback?

So just to clarify some pseudo code:

In the user control contained inside the dialog I would have some code like:

void OnOK(...)
{
// check if any data changed
if (textBox.Text != record.Text)
{
// do a database update
// and
// update cached data which the datagrid is bound to
// call a method on the page to rebind the datagrid only

// ? Force a full page refresh
}
else
{
// do nothing
// asynchronous postback is OK, no full page refresh needed
}
}

The force of a full page refresh is what I would need. In a fat environment like Windows Forms, I would just call Invalidate on the Form. Or IF the DataGrid would be inside an UpdatePanel I would search for it and call Update() on it, but then I would loose the browser caching during back and forward movements. So I was searching through all of the classes if there is something like ScriptManager.UpdatePage or something similar, but have found nothing so far.

So what is the solution here? How can inform the ajax client side script, that it should just go ahead and rerender the whole page instead of just extracting the update panel portions?

Thanks

In the <Triggers> collection of your updatepanel, just add whatever control you want to cause a full refresh as a PostBackTrigger instead of as a AsynchPostBackTrigger.

<asp:UpdatePanel ...>
<Triggers>
<asp:PostBackTrigger ControlID="whateverID" />
</Triggers>
<ContentTemplate>
...
</ContentTemplate>
</asp:UpdatePanel>


Well, that does not work:

a) the UserControl is designed separatly and does not have an update panel and vice versa the dialog is a generic control which just adds a UserControl as a content, so it cannot hardcode if there is any control ID inside which should trigger a full postback

b) I do not want a full postback to occur all the time when the button is pressed, the logic of the button on the server side should determine if a full postback is necessary or not, if not then a partial postback is OK.


I tried to work around now, kind of using your approach by doing this in the OnPreRender or OnChildControlsCreated of the UserControl:

System.Web.UI.WebControls.WebControl btnOK =this.Parent.Parent.FindControl("btnOK")as System.Web.UI.WebControls.WebControl;
if (btnOK !=null)
{
System.Web.UI.Control control = btnOK;
UpdatePanel updatePanel = control.ParentasUpdatePanel;
while ((updatePanel ==null) && (control !=null))
{
control = control.Parent;
updatePanel = controlasUpdatePanel;
}
if (updatePanel !=null)
{
PostBackTrigger pbTrigger =newPostBackTrigger();
pbTrigger.ControlID ="btnOK";
updatePanel.Triggers.Add(pbTrigger);
}
}

So I do find the OK button and I do find the UpdatePanel that contains the button, but it has no effect whatsoever.
The control ID must be right, otherwise I would not be able to find the button with it, but still no PostBack and the Dialog itself is not inside an UpdatePanel.

Trigger Modal Popup from clientside JavaScript

Hi!

How can I trigger a Modal Popup from client-side JavaScript, without having to have it triggered off of a LinkButton server control?

The modal popup demo on the Sample website shows how to show/hide the popup in script.


Would you believe I must have looked at that page dozens and dozens of times and never noticed that blurb down below?Embarrassed

I must admit that one of the problems is that the documentation on the page makes no reference to the BehaviorID property of the ModalPopupExtender... I only found it through extensive Googling...


That blurb was just added last week after we received more than a couple of requests for demo'ing how to programmatically show/hide modalpopups.

Regarding your question about BehaviorID, it is not ModalPopup specific but something that is part of the Toolkit ExtenderControlBase class so all the extenders in the Toolkit have it. You can find more information on that in theExtender Base Class features walkthrough on the Toolkit sample website.


Aaah! Whew! Now I don't feel so bad :)

And thanks for the pointer on the BehaviorID stuff... I think in my haste to see what the toolkit had to offer I didn't dig deep enough to find out about the extras. Just what I needed!

Wednesday, March 21, 2012

troubles with MaskedExtender and maskededitvalidator

This markup

<asp:TextBox ID="TextBoxTelefoneHome" runat="server" CssClass="RequiredInput" Width="17em"></asp:TextBox><cc1:maskededitextender id="MaskedEditExtenderTelephoneHome" runat="server" clearmaskonlostfocus="false"mask="(99) 99999999" targetcontrolid="TextBoxTelefoneHome"></cc1:maskededitextender><cc1:maskededitvalidator id="MaskedEditValidatorTelHome" runat="server" controlextender="MaskedEditExtenderTelephoneHome"controltovalidate="TextBoxTelefoneHome" emptyvaluemessage="Obrigatório" invalidvaluemessage="Inválido"isvalidempty="False" validationexpression="[(]\d{2}[)]\s\d{7}[_\d]"></cc1:maskededitvalidator><asp:Button ID="Button1" runat="server" Text="Button" />

never validates, which it should.

the same with "[(]\d{2}[)]\s\d{7-8}", it seems that only ".+" evaluates. I have no idea how to bring this to work, looks buggish.

Worse still, the page posts back, even when there are (real or not) invalid entries.

Anyone got an idea?

Thanks, Jan

I gave a try to your snippet and it worked every single time. although, the reg expression below the snippet didn't. I wonder if it is because i updated my toolkit dll yesterday, maybe it is a bug that was fixed!


Hi, thanks a lot!

I just did the upgrade and it does not post back anymore. That's a certain relief, but the regex still evaluates incorrectly

For a value "(11) 1234567_" or "(11) 12345678" which should be ok, I both receive an Invalid.

Hmm. I centuplechecked the regex "[(]\d{2}[)]\s\d{7}[_\d]" and it should not be to blame.


Anyone who could help me a bit further?

Jan


your regex is good, it has to be coming from somewhere ele, since it is working on my side. Try to coppy the snippets you provided me with , and use it in a brand new created page. This is one of the issues that makes you pull your hair on your head...,

I hope that you will find a solution.!