Showing posts with label user. Show all posts
Showing posts with label user. Show all posts

Wednesday, March 28, 2012

Track ajax application with google analytics

Hi everyone,

I have an ecommerce application where i use ajax in createUserWizard and in Chart.
To track user activity i use google analytics urchinTracker function.
With ajax a request to the server is made without changing the url of the page, so i have to call urchinTracker function with onreadystatechange.
http://www.google.com/support/analytics/bin/answer.py?answer=33985&topic=7292

The problem is how can i use this code. How i can insert it inside my page.

I have the urchinTracker function in my masterpage:
<scripttype="text/javascript">
_uacct ="UA-XXXXXXXX;
urchinTracker();
</script>

In my content page i have a MultiView control inside the UpdatePanel.
When i skip the step inside the multiView i need to call the urchinTracker function to assign a page filename for the tracking.
How can i do that?

This solution don't work:

ProtectedSub Page_PreRender(ByVal senderAsObject,ByVal eAs System.EventArgs)HandlesMe.PreRender

If mvCreaUtente.ActiveViewIndex = 0Then
Dim sbAsNew System.Text.StringBuilder
sb.Append("<script>")
sb.Append("urchinTracker('/registrazione/step1.html')")
sb.Append("</")
sb.Append("script>")
Me.Page.RegisterClientScriptBlock("ScriptUrlTracking", sb.ToString)
EndIf

End Sub

Thanks

You should set it up in javascript. Tie the endRequest event of the PageRequestManager to a function that will call the urchin tracker function.


Thanks Paul for your reply. Could you please write a simple example of this javascipt code?

Thx


Be happy to. Something like this:

function handleUrchin(ev){ urchinTracker('/registrazione/step1.html');}function pageLoad(){ var prm = Sys.WebForms.PageRequestManager.getInstance(); prm.add_endRequest(handleUrchin);}
Obviously that's pretty simple, and you could add a switch statement or something if you have more than one type of urchin request to do.

Thanks Paul, your reply help me!Wink

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 expand depth 2 collapse to depth level 0.

I have treeview on update panel and loading folders based on user interaction. It works for depth level 2 but at this point clicking the node shows depth level 0 results. is there something I am missing?

here are few lines of crap...

Thanks for you help.

<asp:TreeViewid="SourceTreeView"runat="server"Width="100%"OnSelectedNodeChanged="SourceTreeView_SelectedNodeChanged"OnTreeNodeExpanded="SourceTreeView_TreeNodeExpanded"ShowCheckBoxes="Leaf"ImageSet="Simple"Height="100%"ExpandDepth="1"MaxDataBindDepth="10"NodeIndent="15">

<ParentNodeStyleFont-Bold="False"></ParentNodeStyle>

<HoverNodeStyleForeColor="#5555DD"Font-Underline="True"></HoverNodeStyle>

<SelectedNodeStyleHorizontalPadding="0px"ForeColor="#5555DD"VerticalPadding="0px"Font-Underline="True"></SelectedNodeStyle>

<NodeStyleNodeSpacing="0px"HorizontalPadding="0px"ForeColor="Black"VerticalPadding="0px"Font-Size="10pt"Font-Names="Tahoma"></NodeStyle>

</asp:TreeView>

I am adding nodes per users request using following code, which is same for depth 0,1 and 2.

newNode.Expanded =false;

newNode.ShowCheckBox =false;

newNode.PopulateOnDemand =true;newNode.SelectAction =TreeNodeSelectAction.Select;

treeNode.ChildNodes.Add(newNode);

sg20000:

is there something I am missing

You are missing, that the treeview is not supported in the updatepanelTongue Tied

Check here:

UpdatePanel Control Overview


Maybe you are right and thanks for your help.

I found at some places forward slash was being used, i fixed that and while trying to make it work, made some other changes to node before adding to tree and seems like it is working. I think some nodes had / (creating some escape sequences) or something else to trigger wrapping of tree.

is that treeview on update panel will behave unpredictablly or there are some other issues?


sg20000:

is that treeview on update panel will behave unpredictablly or there are some other issues?

I'm also using treeview with updatepanel, regardless is it not supported.

Main issue which I found that the tree state (selected node, expanded/collapsed nodes state etc.) stays out sync when a postback occurs. Especially when you use any client side capability (populate on demand, enableclientscript=true).

For example:

- Treeview in up

- User coll/exp nodes (no postback yet)

- User select a node, partial postback, selectednodechanged handled for example.

- User select a different node, same as before, but coll/exp state messed up.

- etc.

Without client script features it's ok in up, but slow (big complicated markup, big viewstate etc.)

Monday, March 26, 2012

Trigger does not work

I have a trigger, which is set to lblProgress.Text property. Once the user clicks the button, the code changes the property, but nothing is displayed untill the onclick event finish. Should not be the Atlas asynchronous?

Default.aspx:

<%

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

<!

DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.1//EN""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<

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

<

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

</

head>

<

body><formid="form1"runat="server"><atlas:ScriptManagerID="scriptManager"EnablePartialRendering="true"runat="server"/>

<atlas:UpdatePanelID="UpdatePanel1"Mode="Conditional"runat="server"><ContentTemplate><asp:ButtonID="btnImport"runat="server"Text="Import"OnClick="btnImport_Click"/><divstyle="background-color:Lime"><h1><asp:LabelID="lblProgress"runat="server"Text=""></asp:Label></h1></div></ContentTemplate><Triggers><atlas:ControlValueTriggerControlID="lblProgress"PropertyName="Text"/></Triggers></atlas:UpdatePanel></form>

</

body>

</

html>

Deafault.aspx.cs

using

System;

using

System.Data;

using

System.Configuration;

using

System.Web;

using

System.Web.Security;

using

System.Web.UI;

using

System.Web.UI.WebControls;

using

System.Web.UI.WebControls.WebParts;

using

System.Web.UI.HtmlControls;

public

partialclass_Default : System.Web.UI.Page

{

protectedvoid Page_Load(object sender,EventArgs e)

{

}

protectedvoid btnImport_Click(object sender,EventArgs e)

{

lblProgress.Text =

"Starting Import...";

System.Threading.

Thread.Sleep(5000);

lblProgress.Text =

"That took awhile...";

}

}

I suspect any of two:

1) Call to button_Onclick is not asynchronous, so the page is waiting for the sub to finish

or

2) Setting lblProgress.Text from code does not trigger the trigger.. That would mean a bug in Atlas I guess

Wonder what you think...


Hi,

Atlas being asynchronous means that when you trigger an update for an UpdatePanel, a HTTP request is sent asynchronously to the web server, i.e. you can do other processing on client-side while the request you sent is being processed and the corresponding response is generated.

But the above response is generated when the partial postback ends, i.e. when the page has completed its whole lifecycle and rendered the HTML for the controls inside the UpdatePanel. This means that when btnImport_Click returns, the Label's text is set to "That took awhile..." and it's this text that will be displayed, since it is this text that it is rendered by the Label control and sent in the response from the server.

OK, sounds logical.How do I make the label to refresh in my long running process, which is executed after click?

I have also noticed that UpdatePanel has update property, but not sure how to use it...


Hi,

there are many approaches to monitor a long running task. The one I would take is to spawn a separate thread to run the task (btw checkthis article) and then poll the server at a specified interval to check the task's status and update a progress bar or other kind of progress indicator.

Without Atlas, this could be done using pure Javascript or a meta refresh. Adding Atlas would probably mean using a Timer control to just send the polling requests asynchronously, and update some controls (the progress indicators) inside an UpdatePanel.

Thanks, I was hoping that this could be done simpler using Atlas, if I could only somehow force the UpdatePanel to refresh itself once the lblProgress.text property is updated, my initial thought was that the trigger would do it, but than reading your post I realized that it is waiting for the btnImport_OnClick sub to finish...

Maybe if I need to have btnImport_OnClick running in seperate thread?


You said:

"...But the above response is generated when the partial postback ends, i.e. when the page has completed its whole lifecycle and rendered the HTML for the controls inside the UpdatePanel. This means that when btnImport_Click returns, the Label's text is set to "That took awhile..." and it's this text that will be displayed, since it is this text that it is rendered by the Label control and sent in the response from the server..."

Can I render page early in my onlick sub? before onclick sub will finish?How would I execute UpdatePanel partial postback once my onlick sub sets the lplProgress.text property?


Hi,

rfurdzik:


Can I render page early in my onlick sub? before onclick sub will finish?


no, because the rendering of a page is a stage in its lifecycle and you cannot modify the Page's lifecycle.

rfurdzik:


How would I execute UpdatePanel partial postback once my onlick sub sets the lplProgress.text property?


A partial postback is just a postback performed asynchronously (i.e. using XMLHTTP). From the Page's lifecycle point of view, a classic postback and a partial postback are pretty much the same thing: the Page goes through all its whole lifecycle, like in a "regular" postback. The difference is that only the HTML of the controls inside the UpdatePanels that are updating is injected into the response.

Also what is the porpouse of UpdatePanel1.Update(); ?

Does it force UpdatePanel to do partial postback?


I have also found this interesting article:http://forums.asp.net/thread/1338483.aspx

Seems that he found a way around to execute partial postback... Wonder how would it be possible to execute partial postback in my code:

protectedvoid btnImport_Click(object sender,EventArgs e)

{

lblProgress.Text =

"Starting Import...";

//Here I would like to execute partial postback of Updatepanel1. I have tried UpdatePanel.Update(), but it did not work

System.Threading.

Thread.Sleep(5000);

//THIS LAST MESSAGE IS ONLY SHOWN

lblProgress.Text =

"That took awhile...";

}


<<A partial postback is just a postback performed asynchronously (i.e. using XMLHTTP). From <<the Page's lifecycle point of view, a classic postback and a partial postback are pretty much <<the same thing: the Page goes through all its whole lifecycle, like in a "regular" postback. The <<difference is that only the HTML of the controls inside the UpdatePanels that are updating is <<injected into the response.

I think I understand now, so the page lifecycle will be finished when the last line of the OnClick sub is executed. Is this correct? In this case I guess I need:

1) to have Onclick to instantiate a seperate thread for long running task and leave the task running.. (what happens if the user closes the browser?)

2) My import class calls delegate method (part of my page, setup in import class constructor),how could I make that delegate method to update the lblProgress.text and execute partial postback?

Do you think that using webservice would make more sense?


After doing some research I realized that you were right,btnClick_ONClick sub is part of Postback, that is why postback request can not be generated within.

So now the question would be which aproach to use?

1) The one suggested by you btnClick_ONClick sub would create a seperate thread. Seems like it should be OK to execute Postback from a seperate thread process...

2) Create control in Atlas and have the control to call webservice. Seems like only the control can update progress label settings, server side code can not...

What would be the cons and prons of eighter aproach?


Instead of worrying about creating a new thread, you could separate the single request into 3 separate requests. The initial button click would cause the UpdatePanel to postback where you can change the text to 'loading', and use RegisterClientScriptBlock to inject javascript which would then initiate a second postback. The second postback would then perform your long operation, and would use RegisterClientScriptBlock to inject javascript to fire the final request which would be responsible for changing your text to 'finished' or whatever you decide.

Hope this helps,
-Tony


That is a great idea! I did not think about it. Would this technique allow the text to change several times during the Long Running Process? For example (1,2,3% etc..)

What is the exact injected java script/atlas code to fire the LRP sub? I do not know java script too much... Do you think that that javascript could call asynchronous web method, which would perform LRP and update the label's text? Will the web method have access to the Page object? Thanks,

Rafal


<< and then poll the server at a specified interval to check the task's status

Is not that waste of resources? I was thinking to have the LRP (Long Running Process) to call page's method (via delegate) and force the page to postback itself (partial postback).

What do you think?

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 is causing the user controls OnInit to fire

I have a TextBox inside an UserControl which triggers an update panel on TextChanged. Works really well, but I noticed a problem. When AJAX makes the call back to the server to execute the TextChanged event, it is actually firing the UserControl's overridden OnInit beforehand. Is this normal behavior? I would think that for a page, OnInit should only get called once - when the page is created. There is a good deal of initialization code in my OnInit that really should not be executed again if it does not have to. Is there a way to make the UpdatePanel trigger not fire OnInit?

AJAX postbacks are executed at the server like normal postbacks (the entire page lifecycle is processed from the beginning), so Page.IsPostback = True for AJAX postbacks.

Trigger inside user control wont work

My Page contains a DataGrid inside UpdatePanel and a Filter user control.
I want to set a trigger to the UpdatePanel which refer to a button inside the Filter user control.

I get this error:
A control with ID 'Filter1_btnGo1' could not be found for the trigger in UpdatePanel 'UpdatePanel'.

how do I make this work?

Have you tried:

UpdatePanel.FindControl()

You pass in the control ID.

If you still have a problem, supply some sample code and I'll have another look.


Here is a small and simple code example to show the problem, have a look ...

1. TestUpdatePanel.aspx

<%@. Page Language="C#" AutoEventWireup="true" CodeBehind="TestUpdatePanel.aspx.cs" Inherits="Test.TestUpdatePanel" %>
<%@. Register TagPrefix="UC" TagName="OutSideTrigger" src="http://pics.10026.com/?src=MyUserControl.ascx" %>

<script runat="server">

protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = "Refreshed at " +
DateTime.Now.ToString();
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>UpdatePanel Tutorial</title>
<style type="text/css">
#UpdatePanel1 {
width:300px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<fieldset>
<legend>UpdatePanel</legend>
<asp:Label ID="Label1" runat="server" Text="Panel created."></asp:Label><br />
</fieldset>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btn1" />
<asp:AsyncPostBackTrigger ControlID="uc1_UCButton" />
</Triggers>
</asp:UpdatePanel>
<asp:Button ID="btn1" runat="server" OnClick="Button1_Click" Text="Button" /></div>
<UC:OutSideTrigger id="uc1" runat="server"></UC:OutSideTrigger>

</form>
</body>
</html>

2. MyUserControl.ascx

<%@. Control Language="C#" AutoEventWireup="true" CodeBehind="MyUserControl.ascx.cs" Inherits="Test.MyUserControl" %>

<div style="height:50;width:400;background-color=yellow">
<asp:Button ID="UCButton" runat="server" Text="Button should triger the update panel." />
</div>

Saturday, March 24, 2012

Trigger set to a userControl controls event

Hi Everyone,

I am pretty new to atlas and I am trying to figure out if it can do what i want it to do. I have a gridview control and a user control on a page. The user control has a button that I would like to have trigger the update panel on the aspx webform for the gridview.

When I do this I get a control ID not valid exception on the page. Is there a way to do this or am i only dreaming of better days?

Thanks

Calvin X

Is this not possible or nobody knows?

Were you able to figure this out? I am contemplating performing the same task, so I am interested if you have had some success.

Thank you!

Trigger UpdatePanel with javascript

I have a GridView inside an UpdatePanel. Also on the page is a button, that when the user clicks opens up a modal dialog box. After the user selects an item from the dialog box, the dialog closes which triggers a javascript function. The purpose of this javascript function is to re-bind the GridView, thereby displaying the item just selected from the dialog box.

The javascript function simply triggers a hidden linkbutton that also resides inside the UpdatePanel.

The javascript code:

document.getElementById('ctl00_Main_LinkButton1').click();

The LinkButton code:

ProtectedSub LinkButton1_Click(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles LinkButton1.Click

GridView1.DataBind()

EndSub

This all works fine under IE6. The problem just started when I upgraded to IE7. The LinkButton is no longer getting triggered, so the GridView doesn't update. I've tried this with both the Atlas release, and the Ajax Beta 2 release. Neither seems to do what I want with IE7.

One other thing, if I remove the UpdatePanel from the page entirely, and force a full page refresh, it works fine with IE7.

Has anyone else noticed this? Any ideas on a work around?

hello.

try using fiddler to see the error you're getting.


I downloaded and ran Fiddler, but can see no errors.

I have many apps that use the similar method, and it works in IE6, IE7 and Firefox v2.0 and Apple Browser (don't remember the name - Safari?) hmmm who cares.

Try put your LinkButton outside the update panel.

WS

p.s: my apps use button instead link button. AND I don't use modal window, because it's not supported by many browsers. Instead, I use floating div. Good Luck.


I think the key difference with your solution is that all the logic resides in one page (with the use of floating div). I have tried adding a linkbutton outside the updatepanel, but this makes no difference in my solution.

With the modal dialog, I can trigger the javascript function when the dialog is closed. I tested this my triggering an Alert from my javascript function, so I know the function is being called when I close the dialog.

I next tried adding an HTML Input button outside the updatepanel:

<inputid="Button1"type="button"value="button"onclick="javascript:document.getElementById('LinkButton1').click();"/>

When I clicked this button, itdid trigger a refresh. I'm just not sure why it won't do it automatically once the dialog box is closed. Again, I've proven that the function is being called when the dialog is closed. I'm wondering if this isn't some IE 7 security issue. I've played around with the permissions a bit, but still have no joy.


For what it's worth,

I finally found a solution to my problem. I did a little digging into the JS file for the AJAX ModalPopup control, and modified my javascript accordingly:

window.setTimeout(

"document.getElementById('ctl00_Main_LinkButton1').click();", 0);

Now works with both IE6 and IE7.

Thanks to all for your responses.

Triggering an Updatepanel (b) based on a gridview rowcommand which is inside a UpdatePanel

Hi there,

I have two sections on my aspx page which contain two grids on an aspx page. User and UserDetails.

User section has atab control which contains an update panelupUsers which contains the gridviewgvUsers. I have another grid in a different updatepanelupUserDetails this contains a grid toogvUserAccessKeys. I want to refresh the second updatepanelupUserDetails (basically trigger it) based on the RowCommand in the gvUsers which is in the first update panel. I was able to do this till I added the tab control.

Now it cannot find the gvUsers controlID when I write the trigger.

So is it possible to trigger a different UpdatePanel based on a gridview Control rowcommand event from inside a AjaxControlKit tab control.

Thanks in advance for any suggestions.

Rakesh Ajwani

following is the HTML snipped of the aspx page.

</td><tdstyle="width: 100px"valign="top"><cc1:TabContainerID="pTabs"runat="server"ActiveTabIndex="0"><cc1:TabPanelrunat="Server"ID="tabUsers"HeaderText="Users"Enabled="true"><ContentTemplate><asp:UpdatePanelID="upUsers"runat="server"><ContentTemplate><asp:GridViewID="gvUsers"runat="server"AutoGenerateColumns="False"Width="129px"OnRowDataBound="gvUsers_RowDataBound"OnRowCommand="gvUsers_RowCommand"><Columns><asp:TemplateFieldHeaderText="Users"><HeaderTemplate><tablewidth="100%"><tr><tdalign="left"><asp:Labelrunat="server"Text="Users"></asp:Label></td><tdalign="right"><asp:ImageButtonID="ibAddUser"OnClick="ibAddUser_Click"runat="server"ImageUrl="Images/plus-8.png"/></td></tr></table></HeaderTemplate><ItemTemplate><asp:LinkButtonrunat="server"ID="linkbUserSelect"Text='<%#((System.Data.DataRow)Container.DataItem)["LastName"] + " " + ((System.Data.DataRow)Container.DataItem)["FirstName"]%>'CommandName="ViewDetail"></asp:LinkButton></ItemTemplate></asp:TemplateField></Columns></asp:GridView></ContentTemplate><Triggers><asp:AsyncPostBackTriggerControlID="gvInstitutions"EventName="RowCommand"/></Triggers></asp:UpdatePanel></ContentTemplate></cc1:TabPanel></cc1:TabContainer></td></tr><tr><tdcolspan="2"width="100%"><asp:UpdatePanelID="upUserDetail"runat="server"><ContentTemplate><asp:LabelID="lblInstitution"runat="server"Width="132px"></asp:Label><br/><br/><asp:LabelID="lblLName"runat="server"Width="143px"></asp:Label><asp:TextBoxID="txtLName"runat="server"Width="143px"></asp:TextBox><asp:LabelID="lblFName"runat="server"Width="143px"></asp:Label><asp:TextBoxID="txtFName"runat="server"Width="143px"></asp:TextBox>

<br/><br/><asp:LabelID="lblEmailID"runat="server"Width="154px"></asp:Label><asp:TextBoxID="txtEmailID"runat="server"Width="143px"></asp:TextBox><br/><asp:GridViewID="gvAccessKeys"runat="server"AutoGenerateColumns="False"Width="689px"OnRowCreated="gvAccessKeys_RowCreated"OnRowDataBound="gvAccessKeys_RowDataBound"><Columns><asp:TemplateFieldHeaderText="Application"><ItemTemplate><asp:LabelID="lblApplication"runat="server"Visible="true"Text='<%#((System.Data.DataRow)Container.DataItem)["ApplicationCode"]%>'></asp:Label></ItemTemplate></asp:TemplateField><asp:TemplateFieldHeaderText="Institution"><ItemTemplate><asp:LabelID="lblCampus"runat="server"Visible="true"Text='<%#((System.Data.DataRow)Container.DataItem)["InstitutionName"]%>'></asp:Label></ItemTemplate></asp:TemplateField><asp:TemplateFieldHeaderText="Role"><ItemTemplate><asp:DropDownListID="ddRole"EnableViewState="true"runat="server"></asp:DropDownList></ItemTemplate></asp:TemplateField></columns><EmptyDataTemplate><tablewidth="100%"><tr><tdalign="left">Access Keys</td></tr><tr><tdcolspan="2"><asp:LabelID="lblNoUCARData"runat="server"Text="No Soup For You"Width="217px"></asp:Label></td></tr></table>

</EmptyDataTemplate></asp:GridView><asp:ButtonID="btnSave"runat="server"Text="Save & notify"OnClick="btnSave_Click"/></ContentTemplate><Triggers><asp:AsyncPostBackTriggerControlID="gvUsers"EventName="RowCommand"/></Triggers></asp:UpdatePanel></td></tr>

Hi,

I have a similar problem, except that I am loading UserControls with GridView dynamically into the TabPanels. The GridView have buttons that should fire RowCommand. The TabContainer is within an UpdatePanel. My RowCommand event is not firing, did you find any solutions to your problem?

Thanks.


Hook the gvUsers RowCreate Event, Find the Button using the FindControl. Once Found, create asyncpostbacktrigger programatically set the control id to the found button id and add the trigger in the second update panel trigger collection.

Triggering partial update on text box losing focus

Hi,

I have a form on which I want a user to be able to enter a post code and, when the user tabs out of the field, triggers the population of a drop down list which contains the suburbs the postcode relates to, so the user can then select the suburb.

I have the drop down list in an Update Panel with partial rendering turned on but I can't figure out how to trigger it being refreshed when the control loses focus. I think I need to link it to the OnBlur event using javascript but I'm stuck at that point. Any ideas appreciated...

Thanks,

SimonOK, it was me being dippy. I didn't need to get clever and start hooking client side events, I just needed to set the Render property to "Always" and it fires whenever the text box loses focus.

S

Wednesday, March 21, 2012

Trouble w/ Atlas and Custom User Control

I am trying to create a simple user control that shows a hidden div when an imagebutton is clicked. It works perfectly in a regular page, but in a user control it is conventionally posting back rather than refreshing via Atlas. I have an <atlas:ScriptManager> tag in the page for the control. Below is my code for the control:

<%@dotnet.itags.org. Control Language="C#" AutoEventWireup="true" CodeFile="RatingsBar.ascx.cs" Inherits="UserControls_RatingsBar" %>
<asp:ImageButton ID="showBarGraphButton" runat="server" ImageUrl="~/_Images/bargraph.gif"
OnClick="showBarGraphButton_Click" />

<atlas:UpdatePanel ID="updatePanel1" runat="server" RenderMode="Inline">
<Triggers>
<atlas:ControlEventTrigger ControlID="showBarGraphButton" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:Panel ID="barGraphPopup" CssClass="popupHide" runat="server">
<asp:Image ID="sampleImage" runat="server" ImageUrl="~/_Images/barGraphExample.gif"/>
</asp:Panel>
</ContentTemplate>
</atlas:UpdatePanel>

Below is my code for the default.aspx page:
<%@dotnet.itags.org. Page Title="Hi There" Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"Inherits="_Default" %><%@dotnet.itags.org. Register TagPrefix="uc" TagName="Karmevent" Src="~/_UserControls/Karmevent.ascx" %><%@dotnet.itags.org. Register TagName="RatingsBar" TagPrefix="uc" Src="~/_UserControls/RatingsBar.ascx" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"><title>Untitled Page</title><link href="_Stylesheets/StyleSheet.css" rel="stylesheet" type="text/css" /><atlas:ScriptManager ID="ScriptManager" runat="server" /></head><body><form id="form1" runat="server"><uc:RatingsBar ID="rb1" runat="server" /></form></body></html>
Nevermind, everyone. I re-did the code from scratch and it works. I still have no idea what I did wrong, but it's working now.

Trying to make the CascadingDropDown read only

Hi, i'm trying to stop the CascadingDropDown value from being changed when the item the user is editing (via the formview control) is blocked. I notice there is no read only property on the DropDownList control or on the CascadingDropDown control so I figured the best way to do this was to disable the control and add a hidden field which would post the original value back.

<asp:Label ID="lblSectionIDValue" runat="server" Text='<%# Eval("SectionName") %>' Visible='<%# (bool)Eval("Blocked") %>'></asp:Label>
<asp:HiddenField ID="hfdSectionID" runat="server" Value='<%# Bind("SectionID") %>' Visible='<%# (bool)Eval("Blocked") %>' />
<asp:DropDownList ID="lstSectionID" runat="server" Visible='<%# !(bool)Eval("Blocked") %>'>
</asp:DropDownList>
<ajaxToolkit:CascadingDropDown ID="cddSectionID" runat="server" TargetControlID="lstSectionID" Category="Section" PromptText="-- Please Select --" LoadingText="[Loading sections...]" ServicePath="~/CascadingDropdownsService.asmx" ServiceMethod="GetSectionsList" SelectedValue='<%# Bind("SectionID") %>' Enabled='<%# !(bool)Eval("Blocked") %>' />

However a null value is being posted back instead of the original value. I've tried just about every combination now but nothing works. Without the CascadingDropDown control i can successfully say:

<asp:HiddenField ID="hfdSectionID" runat="server" Value='<%# Bind("SectionID") %>' Visible='<%# (bool)Eval("Blocked") %>' />
<asp:DropDownList ID="lstSectionID" runat="server" SelectedValue='<%# Bind("SectionID") %>' Enabled='<%# !(bool)Eval("Blocked") %>'>
</asp:DropDownList>

which posts the value back.

I think there is a bug in that some value is being sent back if the CascadingDropDown's enabled property is set to false and is overriding the value in the hidden field.

Hi here's a fix which creates a new property called EnabledOverride and works like the Enabled property for the standard controls such as the TextBox.

Edit CascadingDropDownExtender.cs:
============================

Add
-----
private const string stringEnabledOverride = "EnabledOverride";
-----

Add
-----
[DefaultValue("")]
[ExtenderControlProperty()]
public bool EnabledOverride
{
get
{
return GetPropertyValue(stringEnabledOverride, true);
}
set
{
SetPropertyValue(stringEnabledOverride, value);
}
}
-----

Edit CascadingDropDownBehaviour.js:
============================

Add
-----
this._enabledOverride = null;
-----

Add
-----
get_EnabledOverride : function() {
/// <value type="String">
/// Whether the drop down is enabled
/// </value>
return this._enabledOverride;
},
set_EnabledOverride : function(value) {
if (this._enabledOverride != value) {
this._enabledOverride = value;
this.raisePropertyChanged('EnabledOverride');
}
},
-----

Add (at the bottom of _setOptions function)
-----
_setOptions function (at the bottom):

// Disable the control if not enabled
if (!this._enabledOverride) {
e.disabled = true;
}
-----

Hope this helps you as much as it has me :).


You can try enclosing dropdown and cascadingdropdown in a server Div:





           <div runat="server" id="divEstado">



                                <asp:DropDownList ID="ddlEstado" runat="server" ></asp:DropDownList>



                                <cc1:CascadingDropDown ID="cddEstado" runat="server" TargetControlID="ddlEstado"



                                Category="Estado" PromptText="[Select value...]" ServicePath="Services.asmx"



                                ServiceMethod="FillData" UseContextKey="true" ParentControlID="ddlPais" /> 



          </div>



Disabling in code behind:



divEstado.Disabled = true;



Disabling in javascript:



$get('<%=divtrEstado.ClientID%>').disabled = 'disabled';


You can try enclosing dropdown and cascadingdropdown in a server Div:





           <div runat="server" id="divEstado">



                                <asp:DropDownList ID="ddlEstado" runat="server" ></asp:DropDownList>



                                <cc1:CascadingDropDown ID="cddEstado" runat="server" TargetControlID="ddlEstado"



                                Category="Estado" PromptText="[Select value...]" ServicePath="Services.asmx"



                                ServiceMethod="FillData" UseContextKey="true" ParentControlID="ddlPais" /> 



          </div>



Disabling in code behind:



divEstado.Disabled = true;



Disabling in javascript:



$get('<%=divtrEstado.ClientID%>').disabled = 'disabled';

Trying to open a new browser window from within an UpdatePanel and getting Sys.WebForms.Pa

I'm in the process of developing a module for a DotNetNuke portal site. The module hosts an ASP2.0 Wizard control which guides the user through report & parameter selection & then when the Finish button is clicked the module opens a new browser window at a url which hosts the ASP2.0 ReportViewer control.

This all worked OK until I enable AJAX on the site. I've wrapped the Wizard control in an UpdatePanel and although the functionality of the wizard is fine when the Finish button is clicked I get the error"Sys.WebForms.PageRequestManagerParserErrorException: The message from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled."


The wizard_FinishButtonClick handler is doing some housekeeping then calling Response.Write() with a JavaScript string to open the new browser window so I'm guilty as charged. I've tried using DNN's Intermodule Communications to get another module to kick off the browser open but I still end up with the same exception. What would be the best way of getting around this issue ?


ThanksScott

The Wizard control is not supported by Ajax... along with a few other controls... You can work around it by wrapping your Wizard into a Iframe but not within a update panel...


To nitpick, the Wizard controlis supported within an UpdatePanelas long asits contents are converted to an editable template.

Seehttp://ajax.asp.net/docs/overview/UpdatePanelOverview.aspx#UpdatePanelCompatibleControls.


Thanks for your responses guys but I don't think the interaction of the Wizard and UpdatePanel is the issue.

The reason the wizard was wrapped by an UpdatePanel was that

1) the wizard is wrapped by a Drag panel and a collapsible panel. The functionality of the Drag & Collapse panels works fine but any activity within the wizard generates a postback that resulted in the whole thing being relocated back to it's initial start point.

2) I then added the UpdatePanel and I can now move the panel around the page and do stuff within the wizard without it relocating to start point.

3) It was at this point that I started to get the error which is caused by the Response.Write when the wizard Finish button is clicked. There is another method called when the Finish button is clicked and this functionality still works it's just the Response.Write I need to avoid.

I'll be more specific this time - is there a way to open a new browser within an update panel ?

Regards
Scott


Well it seems it is possible to do this. All I had to do was use the script manager to register a client script block from the Finish button click event handler.

the code for this would be for example

protected void wizReport_FinishButtonClick(object sender, WizardNavigationEventArgs e)
{
try
{
string reportViewerUrl = System.Configuration.ConfigurationManager.AppSettings["ReportViewerUrl"].ToString();
System.Type cstype = typeof(class name);
string csname = "PopUpReport";
string script = @."window.open('" + reportViewerUrl + "','_blank','location=no,scrollbars=yes,resizable=yes,top=0,left=0,height=800,width=950');";
ScriptManager.RegisterClientScriptBlock(wizReport, cstype, csname, script, true);
}
catch (Exception x)
{
string s = x.Message;
}
}