Showing posts with label web. Show all posts
Showing posts with label web. Show all posts

Wednesday, March 28, 2012

Tracking Link Clicks

Hi,

I posted this before in the "Web Forms" section, but I was just thinking what I might need is an AJAXian solution.

I'm trying to figure out the best way to track user clicks on links. I could easily do this by making all the links LinkButton's and just use the PostBackUrl property or response.redirect or something like that to send the user on to the page they clicked to.

However, this is not a very good solution because spiders would be unable to crawl these links and I need to have the option of opening the pages from the links in a new browser window at times.

So basically if the HyperLink control had an "OnClick" property that fired before doing the default thing (ie following the link), that would be ideal, but it does not.

So I was just wondering if anyone had any good ideas on how to create a "link" control that would allow search engines to crawl the links, allow me to at times open the linked page into a new browser window (ie target=_blank), and also to record the user clicks into a database?

Would there be a way to use the javascript onclick event to fire some function that calls a service or something on the server to update my database with the click information? If so how would I do that?

Hi,

I just replied in your other thread. Though now I've seen you mention AJAX this would allow you to accomplish a lot more.

Cheers,

Al

Transforming plain ID to adorned ID

I must be missing something obvious here. Suppose I create an ASP.NET Web User Control, and I use a ModalPopupExtender inside it. In the ascx, I set various properties of the extender to refer to controls within the Web User Control, such as PopupDragHandleControlID="TitleText". At runtime, the control with ID "TitleText" gets a more complicated ID on the rendered page (call it an 'adorned' ID, not sure what the offical term is), such as "ctl00_ContentPlaceHolder1_MyCtrl1_TitleText". The behaviour javascript for the extender does things like -

this._dragHandleElement = $get(this._PopupDragHandleControlID);

That wouldn't work with the 'plain' ID, in fact by adding various alert() boxes I can see that _PopupDragHandleControlID has been transformed - somewhere - to the 'adorned' version. I've written an extender that declares and uses ID properties in just the same way, but they don't get transformed from the 'plain' version at runtime. So, I either have to use ugly workarounds like setting that ID programmatically from server-side code (e.g. MyExtender1.BlahID = MyBlahCtrl.ClientID), or ... figure out how to get that transformation to happen automatically like it seems to for ModalPopupExtender. Can anyone point me in the right direction?

(Note, I'm not talking about the TargetControlID property, so ResolveTargetControlID wouldn't come into it, and I'm talking about an extender that's right next to the controls in question.)

Thanks in advance for any leads.

Kevin.

All extender properties that reference ID's are decorated with theIDReferencePropertyAttribute. It helps converts server side ids into client versions so that the behavior can resolve them easily. If you look at the ModalPopupExtender.cs file, the PopupDragHandleControlID has that attribute and so so any other properties that are used to get control IDs.


Do you have any references that confirm that's so and detail where it occurs? The reasons I ask are 1. My extender's properties that ref IDs already have that attribute, and no such conversion occurs, and 2. The documentation for that attribute doesn't mention anything like that, merely that it can be used by designers to help out by giving a list of control IDs at design time - no mention of anything happening at runtime. But if that attribute is the answer and if you have more information on it, please do say so I can figure out why it isn't working for me.

Or does anyone else have details on how the conversion occurs for PopupDragHandleControlID et al?

Thanks in advance for any help

Kevin.


It happens in ExtenderBaseDesignerHelpers.cs file. It is part of the Toolkit framework. If you are building on top of ExtenderControlBase this is taken care of automatically.

Should have included these links earlier

http://ajax.asp.net/ajaxtoolkit/Walkthrough/CreatingNewExtender.aspx

http://ajax.asp.net/ajaxtoolkit/Walkthrough/ExtenderClasses.aspx


Aha. In fact, I had a hand-rolled extender built with ref to various online docs rather than one done as per that walkthrough, which when followed showed up I'd not got the ECB derivation stuff right. In the interim, I'd done some tracing through the ACT code and you're quite right, that attribute is used as a signal for the base classes to apply some transformation before serialising. Funny the docs don't mention that. Anyway, thanks for the pointers - it's running ok now.

Kevin.

TreeView Ajax

Hello, I want to use a TreeView in a web form, but i want to use ajax, and i can't use it inside a updatepanel, so how i can use a treeview by using ajax.

Hi kadben,

TreeView is not compatible with partial-page updates, and is therefore not supported inside anUpdatePanel control

The following ASP.NET controls are not compatible with partial-page updates, and are therefore not supported inside anUpdatePanel control:

TreeView andMenu controls.

Web Parts controls. For more information, seeASP.NET Web Parts Controls.

FileUpload controls when they are used to upload files as part of an asynchronous postback.

GridView andDetailsView controls when their EnableSortingAndPagingCallbacks property is set totrue. The default isfalse.

Login,PasswordRecovery,ChangePassword, andCreateUserWizard controls whose contents have not been converted to editable templates.

TheSubstitution control.

Validation controls, which includes theBaseCompareValidator,BaseValidator,CompareValidator,CustomValidator,RangeValidator,RegularExpressionValidator,RequiredFieldValidator, andValidationSummary control.

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.

Treeview Control How can I trap a callback function

In my web application I have an Ajax Treeview control which populates its child nodes via AJAX, and all is working beautifully except that all our pages turn on a "spinny" image whenever there is a postback either full or partial my problem is how can I trap the completion of the ajax postback so I can turn the spinny off?

I cannot find a treeview event that I can trap on the client side to do this.

I expect someone has ran into this issue before so any help would be gratly appriciated.

I have only recently started using AJAX and so far everything I have seen has been really good but I would to solve this issue.

Cheers

John

How are you populating the tree? What "Ajax Treeview control" are you using?

You should be able to attach a callback handler that will let you get rid of the "spinny", but without knowing your approach I can't recommend how to do this in your instance.

-Damien


Hi Damien

Here is the markup for the treeview I have removed the styling for berevity

<asp:TreeViewID="tvwProcess"runat="server"EnableClientScript="true"OnTreeNodePopulate="GetChildren"PopulateNodesFromClient="true"Style="overflow: auto; height: 490px">

</asp:TreeView>

GetChildren is a serverside method which populates the expanded node

Does this give you enough info?

Thanks

John


You should be able to use the ClientScript.GetCallbackEventReference to get a reference to the callback and then hide the image using the callback method (seehttp://west-wind.com/weblog/posts/2302.aspx for an example).

Hope this helps...

-Damien


Hi Damien

re:

You should be able to use the ClientScript.GetCallbackEventReference to get a reference to the callback and then hide the image using the callback method (seehttp://west-wind.com/weblog/posts/2302.aspx for an example).

I tried your suggestion and got the example from west-wind working fine and also this example from Microsoft http://msdn2.microsoft.com/en-us/library/ms153106.aspx

the problem I still have with the treeview is what event to attach it to. The logical option would be the "OnTreeNodeExpanded" but that looks for a server side methodAm I missing something?CheersJohn

Hi,

At the client side,the"OnTreeNodeExpanded" is the click event of the parent Node.

treeview in Multiview clientscript problem in new beta

Hi,

I have a problem with one of my web page... for debugging purpose I created a simple test webpage to explain the problem.
Here it is:
An updatepanel containing a multiview.
In this multiview there's 2 view, each containing a tree view and a button to go to the other view.
The default activeview is the first one.

My problem is that only the treeview in the first view works.
The treeview in the 2nd view crashes with error "Microsoft JScript: 'TreeView2_Data' is undefined." when I click a node.
Of course if I set the enableclientscript property of the treeview to off then it works okay but it does a partial postback at each node collapse-expand...

My guess is that the clientscript is not injected correctly on view change but how can I fix that ?
Btw it used to work before I updated to Beta 1.0

Thanks a lot !

Jean-Sébastien Roy

I was able to repro it and report it to the developer..

thanks for the report....

Andres


Hi,

The TreeView control is not supported inside UpdatePanels in Atlas 1.0. A future release of Atlas will support this scenario. In Atlas 1.0 you can have the TreeView outside the UpdatePanel.

Thanks,

Eilon


Thanks to you both for the fast answers !

Placing a TreeView inside an UpdatePanel is not supported on the Beta. Please look a the following documentation page (under the "UpdatePanel Compatible Controls"):http://ajax.asp.net/docs/Overview/intro/partialpagerendering/updatepanelOverview.aspx. Full support for all controls will be available on the next release of ASP.NET.

Thanks,
Federico


I had a same problem. Seems like its not supported in Beta version. Does anyone know of a workaround?

Thanks


Hi,

UpdatePanel control is used for only partial updating/partial_page rendering. You can not use the updatePanel control for Treeview and someother controls like MenuView and FileUpload.

If you need more help on this check in below link under UpdatePanel Control.

http://ajax.asp.net/default.aspx

Pradeep Kumar

Saturday, March 24, 2012

Trigger problem

Hello, I have an custom control with an event, Something like this

Partial

Class CustomControl_SearchInherits System.Web.UI.UserControl

End Class

Therein i have declared an event:

PublicEvent SelectedIndexChanged(ByVal senderAsObject,ByVal eAs System.EventArgs)

and in the html i have created an Listbox

<ASP:ListboxSelectionMode="Multiple"ID="_Listbox"runat="server"AutoPostBack="true"Height="100%"Width="400px"/>

then on the event Listbox.selectedIndexChanged i raise the event SelectedIndexChanged.

ProtectedSub Listbox_SelectedIndexChanged(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles _Listbox.SelectedIndexChanged RaiseEvent SelectedIndexChanged(sender, e)EndSubNow when i try to hook up a selectedIndex event (from my custom control) on the TRIGGER property from the update panel, it wont work, Why not?, It doesnt even apear in the event property's of my custom control

Could you specify the control composition?

I mean , whether the update panel holds an instance of your CustomControl_Search, or the ListBox itself.

If it is the first case, it is quite natural that the update panel cannot be triggered by the SelectedIndex event of the list box.

Probably you could paste some more code here ?

Yani


Ok. Here is some more code:

This is the definition of the custom control

<%@.ControlLanguage="VB"AutoEventWireup="false"CodeFile="Search.ascx.vb"Inherits="CustomControl_Search"%>

<tablewidth="100%"height="100%"cellspacing="0"cellpadding="0"border="0"id="TableNav">

<trheight="12px">

<tdrowspan="4"style="width: 400px"class="IL">

<ASP:ListboxSelectionMode="Multiple"ID="_Listbox"runat="server"

Height="100%"Width="400px"/></td>

</tr>

</table>

ProtectedSub Listbox_SelectedIndexChanged(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles _Listbox.SelectedIndexChanged

RaiseEvent SelectedIndexChanged(sender, e)

EndSub

PartialClass CustomControl_Search

Inherits System.Web.UI.UserControl

' declare events

PublicEvent SelectedIndexChanged(ByVal senderAsObject,ByVal eAs system.EventArgs)

PublicEvent Find_Clicked()

' handle event (in customcontrol)

ProtectedSub Listbox_SelectedIndexChanged(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles _Listbox.SelectedIndexChanged

RaiseEvent SelectedIndexChanged(sender, e)

EndSub

EndClass

Then I use this custom contol in an aspx page, with 4 update panels, witch have a trigger on the SelectedIndexChanged event raised by Searchpnl

<tdcolspan="3"><uc4:SearchID="Searchpnl"runat="server/></td>

<cc1:UpdatePanelID="UpdatePanel1"runat="server"RenderMode="Inline">

<ContentTemplate>

-- Content --

</ContentTemplate>

<Triggers><cc1:ControlEventTriggerControlID="Searchpnl"EventName="SelectedIndexChanged"/></Triggers>

</cc1:UpdatePanel>

But I the whole page is updated, and I won't only the update panel to be updated. (that's where its for).

I can't see the SelectedIndexChanged event in the property's. I can't see it in the task pane from the updatepanel either.

Thanks in advance


If you want to get only the update panel updated, you need to put your search control into the update panel.

Other wise it wouldn't know whether to make a regular page post back or an ajax one.

If it does not work try registering your search control in the script manager

ScriptManager1.RegisterAsyncPostBackControl(Searchpnl);

Cheers,

Yani


While we work closely with the ASP.NET AJAX team when developing the Toolkit, they're the real experts on general ASP.NET AJAX issues. Your problem doesn't seem to be directly related to the Toolkit, so we'd appreciate if you considered posting to one of theother newsgroups such asAJAX Discussion and Suggestions. Your post will be more helpful to others looking for similar advice if it's in the right place. Thank you!

hi,

how can an activex control trigger an event of the parent form's control?

for example, I have an activex control which is a button that when clicked, it will output the content of a textbox.

Public Function setText(txt As String)
msg = txt
End Function

Private Sub Button_login_Click()
MsgBox msg

End Sub

After the msgbox is displayed, I want to clear the text in the textbox located in the parent form.

Any idea?

thanks!

Sheila

Triggers for update panel

I have a web page (aspx) that has on it 2 controls (ascx) - one of the controls has an update panel with functionality for it etc. - I want to trigger the update function from the second control that has a linkbutton on it.

Is this possible?

TIA

Yes. Update panel has Triggers element which can be used as follows
 <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <Triggers> <asp:AsyncPostBackTrigger ControlID="lnkButton" EventName="Click"/> </Triggers> </asp:UpdatePanel>

It would seem so - but if the trigger and the update panel are in different ascx files they can not see each other - even if those ascx files exist as controls on the same aspx page

You can explicitly call Update method of another UpdatePanel like this:

UpdatePanel1.Update() ;

Assumption: LinkButton is in UpdatePanel2 and the above code is written in event handler for LinkButton click event.

Generally, you have this kind of scenario in Master-Detail relationship. There is tutorial onhttp://ajax.asp.net site about this.


Okay I dont think you are looking at what the question says - because this doesnt work - unless you can point me to the specific tutorial I cant find the one you are talking about

here is a simple picture that diagrams what I am trying to do

Page1.aspx has two controls on it - both controls are ascx files (Control1.ascx and Control2.ascx)

Control1.ascx has an image button that when clicked is to trigger the UpdatePanel on Control2.ascx

Example

Wednesday, March 21, 2012

Trouble getting AJAX Extension 1.0 to work in VWD

I have installed the ASP.NET 2.0 AJAX Extension 1.0 on my computer. I tried creating an AJAX enabled web application in Visual Web Developer and the UpdatePanel controls along with all the other new AJAX keywords were not recognised even though the toolbox had been updated with the controls. I thought it might be my errors in the code, so I downloaded the sample code for the ToDo list application tutorial onwww.asp.net/ajax and I had the same problem.

That way I can be sure that it is my computer! I have Microsoft .NET Framework 1.0, 1.1, 2.0 and 3.0 installed. I have tried a reinstall of AJAX Extension 1.0 and have made sure that I have selected 'AJAX Enabled project' at the start up screen.

What is the problem?

Check out this link

http://asp.net/AJAX/Control-Toolkit/Live/Walkthrough/Setup.aspx



Sorry but that really wasn't that helpful! I just have the AJAX Extensions 1.0 NOT The Control Toolkit. I can't get the first bit to work so I can't use the toolkit anyway! When I tried installing the vsi file for the toolkit it didn't install the components properly.

What is the problem?


I think because you r using VWD, you will not be able to install vsi template.

and to use Microsoft AJAX Control you will have to download the toolkit

After downloading the toolkit just follow steps from above link

in "Configure Visual Studio 2005 and Visual Web Developer" section

I hope it helps.


I realised the problem.

I needed to install Service Pack 1 for VWD before it would fully recognise the AJAX Extensions. That solved it and I could then install the control toolkit

Trouble with Control Toolkit

Hello,

I am using the ASP.NET Ajax Control Toolkit with Visual Web Developer. I am not able to see the controls from the toolkit when I drag and drop. The only way to see the object is to find them in the properties box and adjust properties but not be able actually see them.

It would be appreciated if someone could explain how to install the control toolkit in Visual Web Developer. B/c i feel i have installed in the wrong manner.

Hi,

Everything sounds like it was setup correctly. Most of the components in the Toolkit areExtenderControls which just add new properties to the controls they extend in the designer.

Thanks,
Ted

Thank You that is what I was looking for!


Thanks that was what I was looking for!

Trouble with initiating a javascript function with a hyperlink

I have a page that is using ajax (javascript) to connect to a web service which does a number of back end features and then returns a value. This is being initiated from a hyperlink. I am having a hard time with the correct syntax for this. I am hoping for some help. The communication with the webservice works. I am just having trouble with the javascript syntax.

The link is as follows:

<a href="http://links.10026.com/?link=javascript:SubmitVote(1488,7cb84341-9a9f-4cd5-a714-550879c3dfa2);">Vote</a>

I want it to work with the following script (which has been simplified):

<

scriptlanguage="javascript"type="text/javascript">

<!--

function

SubmitVote(Num1, String1) {

funcRut = SubmitVote.SubmitVote(Num1.value, String1.value, OnComplete, OnTimeout, OnError);

return

true;

}

function

OnComplete(value) {

alert(value);

}

function

OnTimeout(value)

{

alert(

"OOPS - Timeout");

}

function

OnError(value)

{

alert(

"Oops - ERROR");

}

// -->

</

script>

Thank you kindly.

Hi,

i think you have just forgotten two single quotes for the second parameter:

<a href="http://links.10026.com/?link=javascript:SubmitVote(1488,'7cb84341-9a9f-4cd5-a714-550879c3dfa2');">Vote</a>

Regards
Marc Andre


Danke Marc. I knew it had to be something simple...it always is. I appreciate the effort.