Showing posts with label postback. Show all posts
Showing posts with label postback. Show all posts

Wednesday, March 28, 2012

Trace="True" and partial postbacks

When a page is set to Trace="True", partial postback fail with an error stating that there is a problem parsing the page and the reason could be because Trace is set to True. OK, so how are we supposed to trace our pages then?

You can use Tracing but you can't use the pageouput option (so that the trace gets displayed on your webpage). That's causing the error. What you can do is set the page output to false.

<traceenabled="true"pageOutput="false"/>

If you want to view the tracelog, you can view it usingtrace.axd(http://somewebsite/trace.axd)

tree view + no postback + update panel

setup:

master page - content page layout

On my content page I want two update panels, one to contain a tree view dynamically generated from a database and the other to contain dynamically generated data (also pulled from a database) based on what is selected in the tree view. It is my understanding that tree view cannot be in an update panel. What is the best strategy for accomplishing this? I don't want a postback to be performed when an item is selected in the tree view. In other words, I don't want the entire page (form) refreshed just because an item in the tree view is selected.

Thanks in advance for any help.

If your treeview doesn't change the contents after the PageLoad, you may be able to have it in an update panel. We found that it doesn't work well if you add nodes to the treeview when you click a parent node, but if you load the full treeview it may be ok. If you need to dynamically add nodes as you click, you would probably need something like the TreeView that telerik has. We were looking at that one until we decided to do our page differently, and that control is not free, but seems to work nice.

The 2nd update panel would have a grid view in it. From the grid view I would add or edit content. If I added content the tree view would need to be refreshed without a full page postback to display the newly added item.

From the sounds of it, this isn't possible with strictly MS controls at the moment.


I just finished this very thing. The page starts with just a pulldown and then based on that value creates a Treeview dynamically without refreshing the page. Then clicking on a node causes another update panel to refresh with specific information.

Pretty convoluted with half Telerik and half MS. The full Telerik approach (Treeview and Update panel) looks easier, but we are using MS AJAX.

My older version of the Treeview (5.3) does not work with MS update panel, so I need to upgrade. I'm not too happy about it, but it seems to work well.

WISH LIST: A direct JavaScript method to postback to an MS update panel. As it is this seems to be the best approach:

http://forums.asp.net/thread/1541012.aspx


I followed the instructions on that thread and I have my update panel refreshing from javascript code. How do I call a javascript function when a tree node is clicked?

in the Telerik Treeview there is a property called "onBeforeNodeClick" and you can set that to the name of a javaScript function to fire when a node is clicked and before postback.


So, I did

myTreeNode.NavigateUrl ="javascript:postBackHiddenField('hardcodedhiddenfieldcontrol','" + uniqueIdentifierOfTreeNode +"')"function postBackHiddenField(hiddenFieldID, clickedID){alert("works");var hiddenField = $get(hiddenFieldID);__doPostBack(hiddenFieldID,'');}
 
I want to use the uniqueIdentifierOfTreeNode in order to modify the select paramter of a gridview in the update panel I'm refreshing from __doPostBack. I have no idea. Any help is appreciated. Is this the best approach to take even?

I forgot to mention the postback and refresh of the update panel is working as I have a label refreshed with the system time.
Nevermind, it looks like I came up with a reasonable solution that works.

Treeview in Ajax.Net

Hi,

I want to use Treeview control using Ajax.Net, that should refreshed without postback.
Please provide me guidance or sample code.

Thanks in Advance.

The Treeview control is not supported in the current release of ASP.NET Ajax. I have heard of people getting it working though by manually doing changes in the prerender event, although when we tried that there were always some errors. I would suggest the telerik Tree control, although it isn't free..

Monday, March 26, 2012

Treeview, how to remove style on preselected node

In my .NET 2.0 project and I'm using a TreeView with Atlas so the page doesn't postback. When the page loads the first time, it also preselect a node based on a value saved in the DB. The style applied on this node doesn't change when user selects another node. However, the style on the node user selected is removed once user selects another node. I'm guessing there's a javascript variable I need to set on page load?

T"he style applied on this node doesn't change when user selects another node. However, the style on the node user selected is removed once user selects another node."

So the node loses it style when what occurs? I'm not quite sure what you mean by that?
Just so you know though the TreeView control doesn't cause a postback in terms of navigating through the tree. If you need to apply a certain style to the TreeView just look at the options for it here.

http://www.asp.net/QuickStart/aspnet/doc/ctrlref/navigation/treeview.aspx

That should give you a good starting place for how to work with the TreeView control both on the server side and client.

JoeWeb

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.

Saturday, March 24, 2012

Trigger PostBack to an UpdatePanel from a separate UserControl?

Hi,

I like putting stuff in separate usercontrols, since i do a lot of gridview templatefields and putting several of these gridviews in one page messes up my .aspx. with user controls, i can just worry about the layout and design on my .aspx pages.

i have one problem though with my new personal approach,

example is i created a "Picture Gallery" site:

1. I put a FileUpload Control (which does NOT work in an UpdatePanel), a button that contains upload tasks (save file, add records to sql db), and an SQLDataSource control, in an AjaxControlToolkit ModalPopup. I then put them all in a UserControl, ill call it Upload.ascx.

2. I create another UserControl, which i shall call Gallery.ascx. This contains a DataList control, that displays the pictures and relative info from the sql db. DataList is connected to an SQLDataSource control. I put them in an UpdatePanel, so i can add an UpdateProgress control.

3. I then put Upload.ascx and Gallery.ascx in my Default.aspx

Ok it works fine, File uploads, records get inserted to the sql database, ModalPopup works! I have one major problem though, everytime I press the Upload Button from Upload.ascx, I need to call DataList.DataBind() from Gallery.ascx's Page_Load event, or simply UpdatePanel.Update(), since it will cause Page_Load to fire from Gallery.ascx UserControl. How do I do this?

Hi,wreck_of_u

We have a few cases were we use a button on our pages that aren't visible, and they are being programatically clicked to refresh our page.

Do it like this:

PageA.aspx:

<%@. Page Language="C#" %>

<%@. Register src="http://pics.10026.com/?src=Gallery.ascx" TagName="Gallery" TagPrefix="uc1" %>
<%@. Register src="http://pics.10026.com/?src=Upload.ascx" TagName="Upload" TagPrefix="uc2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
Upload1.Button1clientID = Gallery1.Button1clientID;
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>

</div>
<uc1:Gallery ID="Gallery1" runat="server" />
<uc2:Upload ID="Upload1" runat="server" />
</form>
</body>
</html>

Gallery.ascx:

<%@. Control Language="C#" ClassName="Gallery" %>

<script runat="server">

protected void Button1_Click(object sender, EventArgs e)
{
}

protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = DateTime.Now.ToString();
}

public string Button1clientID
{
get
{
return Button1.ClientID;
}
}

</script>

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<div style="visibility:hidden"><asp:Button ID="Button1" runat="server" OnClick="Button1_Click" UseSubmitBehavior="false" Text="Button" /></div>
</ContentTemplate>
</asp:UpdatePanel>

Upload.ascx:

<%@. Control Language="C#" ClassName="Upload" %>

<script runat="server">
private string buttonclientID = "";
public string Button1clientID
{
set
{
buttonclientID = value;
}
}
</script>

<script type="text/javascript">
function submitForm(frameName,upload){
// document.forms[0].action="PageA.aspx"
// document.forms[0].target=frameName;
// window.setTimeout(function(){
// var uploadE=document.getElementById(upload);
// uploadE.parentElement.appendChild(document.createTextNode(uploadE.value));
// uploadE.parentElement.replaceChild(uploadE.cloneNode(true),uploadE);
// },100);
// document.forms[0].submit();
document.getElementById("<%=buttonclientID %>").click();
}
</script>

<div id="Div1">
<input type="file" name="upload" id="upload" />
<button onclick="javascript:submitForm('hiddenFrame','upload')">Upload</button>
<iframe name="hiddenFrame" src="http://pics.10026.com/?src=blank.htm" id="hiddenFrame" style="display: none">
</iframe>
</div>

I have used this mothod to fix some problems :

http://forums.asp.net/t/1117770.aspx

http://forums.asp.net/t/1115934.aspx

http://forums.asp.net/t/1116851.aspx

You can also see these threads for more help.

Let me know if you need more info.

If this help you,don't forget mark it as a answer.Thanks!

An Ajax Alternative for FileUpload!!!!

We've all embraced Ajax as a revolutionary technology, but many of us forget (or are not aware) of asynchronous posts in the times before XmlHttp requests. Our good old friend the IFrame used to be the preferred option for asynchronous http communications. Because an iframe is in essence it's own browser window, it can be used to fire off asynchronous requests (both POST and GET). However, even more important is an IFrame's ability to be a 'target' of a form POST. By adding an IFrame to the page and setting it as the target of the form post, you can in essence create an asynchronous file transfer.

For more help about Ajax Alternative for FileUpload, Please check: http://blogs.infragistics.com/blogs/tony_lombardo/archive/2007/04/09/file-uploads-where-s-the-ajax.aspx


You can see this post

http://forums.asp.net/p/1123812/1770607.aspx#1770607


Hi, This is a great technique.


But it does not work for me in Firefox. Does it work for you in FF? works fine in IE7

Trigger stops working after first postback

Hi,

First let me explain the basic situation. I have a page with 2 list boxes (there are more, but for the sake of argument, take 2). The Box A contains a list of items. The Box B contains the list of items chosen by the user. There is an imagebutton that when clicked, moves the selected ListItem from Box A to Box B, and there is another imagebutton that moves a selected item from Box B to Box A.

Pretty straightforward. The list boxes are in separate update panels because they each have other triggers associated with them that are not common to the other. Here is what happens, when the move button is clicked the first time, the transfer works. After that, it's as if there is no postback at all.

Here is how I have it setup:

<

atlas:UpdatePanelID="LeftColPanel"runat="server"Mode="Conditional">
<ContentTemplate>
<asp:ListBoxID="LeftCol"runat="server"Rows="10"Width="140"/>
</ContentTemplate>
<Triggers>
<atlas:ControlEventTriggerControlID="MoveToLeftCol"EventName="Click"/>
</Triggers>

<

asp:ImageButtonID="MoveToLeftCol"runat="server"ImageUrl="pics/left.gif"OnClick="MoveToLeft"/>

and similarly for the second List Box.

What I don't understand is why it works the first time, and not after that? Any help would be appreciated.

Thanks,

i also have the same problem with a gridview
i don't know the solution yet but do you have some strange character in your listbox?
like single quote, or something else

or maybe you already found the solution :)

if yes please let me know

thanks

Trigger update panel from JavaScript

I have a Telerik Treeview OUTSIDE an update panel, and would like to trigger an asynch postback in the update panel and pass in parameters from the Treeview.

It is easy enough for me to capture the click event in JavaScript, including all node values.

The trick is:

How do I trigger the update panel and pass in those parameters from JavaScript?

Look here:

http://forums.asp.net/thread/1541012.aspx

Trigger wont cause a PostBack (Inside UpdatePanel)

When I click my LinkButton inside my GridView I want the page to postback and a pdf to be streamed to the browser.
It is streamed but the page dont Post so nothing is received.

What am I doing wrong here?

1Protected Sub GridView1_RowDataBound1(ByVal senderAs Object,ByVal eAs System.Web.UI.WebControls.GridViewRowEventArgs)Handles GridView1.RowDataBound23If e.Row.RowType = DataControlRowType.DataRowThen45Dim ptAs New PostBackTrigger()67pt.ControlID = e.Row.FindControl("lbtnPrintInvoice").UniqueID8UP1.Triggers.Add(pt)910End If1112End Sub

Hi,

in docs:

http://asp.net/AJAX/Documentation/Live/mref/T_System_Web_UI_PostBackTrigger.aspx

Remarks

Use thePostBackTrigger control to enable controls inside anUpdatePanel to cause a postback instead of performing an asynchronous postback.

Use theRegisterPostBackControl(Control) method of theScriptManager control to programmatically register a postback control. You can then call theUpdate() method of theUpdatePanel control when the trigger control performs a postback.

note

Programmatically addingPostBackTrigger controls is not supported.

So basically you need to use ScriptManager's RegisterPostBackControl method to do it.


Hmm I can apreciate that but how do I call my lbtnPrintInvoice inside Gridview1 thats the question... The below code doesnt work for some reason ;)

1<Triggers>2<asp:PostBackTrigger ControlID="lbtnPrintInvoice" />3</Triggers>

Gives the error:

A control with ID 'lbtnPrintInvoice' could not be found for the trigger in UpdatePanel 'UP1'.


You really read the previous reply?Big Smile

Does this help:

Protected Sub GridView1_RowDataBound1(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound

If e.Row.RowType = DataControlRowType.DataRow Then

ScriptManager.GetCurrent(Me).RegisterPostBackControl(e.Row.FindControl("lbtnPrintInvoice"))

End If

End Sub

-- EDIT: Fixed this reference in the code


Jeeze! I wans't aware you could actually call the scriptmanager like that since mine is in the masterpage I never thought I could adress it directly

Thanks a bunch for the solution though for people that might want the complete solution I added the page reference in the below code as well.

1Protected Sub GridView1_RowDataBound1(ByVal senderAs Object,ByVal eAs System.Web.UI.WebControls.GridViewRowEventArgs)Handles GridView1.RowDataBound23If e.Row.RowType = DataControlRowType.DataRowThen4ScriptManager.GetCurrent(Me).RegisterPostBackControl(e.Row.FindControl("lbtnPrintInvoice"))5End If67End Sub

Oh and I also tried to do it in RowCreated, never would have worked out.


ScriptManager has good utility methods. It's worth to know about them. I edited & corrected the code. Made a typo as I typed directly to the post.

Triggering a Partial Postback with a Button Inside a Repeater

Hi All,

I have a Button inside a Repeater inside an Updatepanel and I would like to trigger the update of another updatepanel. The strategy I have utilized thus far is to add a commandname parameter to the button, passing it to the itemcommand parameter of the repeater. I then add a asyncpostback trigger for the 2nd updatepanel for repeater.itemcommand. The code that I have for the itemcommand executes, but the problem is I get a full page refresh. If anyone has a work around for this problem or know of a way to do something similar using a different strategy, I would greatly appreciate your help =) Thanks in advance!

I would also like to add that I have tried this with the repeater outside of the updatepanel and it still does not work.
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!

Triggering custom client-side javascript after an asp.net ajax postback

I'm working on a form that I wrote a ton of javascript for. The page is also processed server-side through asp.net.

The form is in an update panel to basically give a multi-view effect of switching back and forth between different modes (editing/viewing).

I want my javascript to trigger every time I go into edit mode. To accomplish this, I came up with the following 'hack' to do it.


<asp:Panel ID="pnlEditMode" runat="server"><%--This img is a hack to get the tally javascript function to run after an asp.net ajax postback--%><img onerror="tally(this);" src="http://pics.10026.com/?src=" style="display: none;" /></asp:Panel>

It basically just shows/hides the panel depending on what mode it is.

It works great, just wondering if there's a better way.

Thanks


It looks like you should be using the ScriptManager.RegisterStartupScript() method.

ScriptManager.RegisterStartupScript(this.updatePanel,

this.updatePanel.GetType(),

"tally",

"tally()",

true);

Call it sometime during the asynchronous PostBack request.

Mark

Triggering full page postback from control inside updatepanel.

Hi,


I was wondering if it was possible for a control inside an updatepanel to cause a full page postback.

I have a button in an updatepanel that when pressed, modifies some controls outside of the updatepanel. I need the page to do a full postback so that the rest of the controls are updated when the button is clicked. I can't put those other controls in another updatepanel, because one of those controls is a treeview.

Should I just remove the update panel, or is there a programmatical way to cause a full postback ?

Thanks in advance, Max

Try this:

<asp:UpdatePanel ID="UpdatePanel1" runat="server"> <Triggers> <asp:PostBackTrigger ControlID="Button2" /> </Triggers> <ContentTemplate> <asp:Button ID="Button1" runat="server" Text="Click me for an async postback." /> <asp:Button ID="Button2" runat="server" Text="Click me for a full postback." /> </ContentTemplate></asp:UpdatePanel>

And I was wondering what the postbacktrigger's where for !Confused.

Thanks


And I was wondering what the postbacktrigger's where for !Confused.

Thanks

Wednesday, March 21, 2012

trouble with PostBack in UserControl

I have a trouble with partitial postback via AJAX.

I derived from LinkButton, added some javascipt (put argument in hidden filed and get this argument on server from hiden field) to control and in Render not rendering ID (I dont need ID because I not user server side mechanism for handling control after postBack.)

Now I try work with my new Control:

I putting my derived LinkButton inside UpdatePanel on the page.
And I have not any troubles. When Click on LinkButton - AJAX send partitial PostBack to server.

But when I put my derived LinkButton inside UserControl, and this UserControl put on page inside UpdatePanel - so I have a trouble: when I click on me LinkButton, so page send full postBack to server as if I not use UpdatePanel.

But if I render ID of LinkButton to html, so it's work in page and in userContol without any trouble. (but I don't want render ID because it's many not usefull chracters.)

May be samoebody know what I can do for resolving this situation without rendering ID (it's strangely that it work without LinkButton ID on page and not work inside UserControl?

thanks

Hi psyafter,

Take a look at this link:

http://msmvps.com/blogs/luisabreu/archive/2007/02/01/getting-a-full-postback-from-within-an-updatepanel-without-using-a-postbacktrigger.aspx

Regards,


You can add an event to the usercontrol and fire it on the link button's click event... then add this new event as the trigger.


2Participant:
first post:
I know it, but I have ID in LinkButton, and just not render it to html. And its work in page, but not work inside UserControl that on the page.

second post:
I can't add new event to triger, because LinkButon is inside UserControl, the UserControls is inside UpdatePanel on the page.

may be I can add something via Page.Register... or something like it?


Hi

I think this post can help you:

Can I specify a UserControl custom event as a Trigger for update panel on Parent page? :http://forums.asp.net/p/1123812/1785025.aspx#1785025

If you need more information,please let me know.

Thanks