Showing posts with label usercontrol. Show all posts
Showing posts with label usercontrol. Show all posts

Monday, March 26, 2012

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 load of usercontrol after page has rendered

Is there a way of triggering a usercontrol to load into an asp:placeholder right after the page has rendered to the screen, similar in the waywww.pageflakes.com does it.

I have a usercontrol that is quite slow to load up because it displays a graph that runs a chunky stored procedure. At the moment the whole page doesnt display until the user control has finished loading in.

Any way of doing this?

Anyone know a solution to this?
Please does anyone know?
might help...http://www.codeproject.com/Ajax/aspnetajaxtips.asp

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 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!

Triggers

Hi to all.

So, I create buttons in a usercontrol after it i want to create triggers on this buttons in page. Is it possible?

I tried to do something like this on page

private

void FindButton(Control control)

{

foreach (Control phin control.Controls)

{

if (ph.Controls.Count > 0)

FindButton(ph);

if (phisCMSLinkButton)

{

ControlEventTrigger cet =newControlEventTrigger();

cet.ControlID = ph.ID;

cet.EventName =

"Click";

((

UpdatePanel)this.FindControl("UPContent")).Triggers.Add(cet);

}

}

}

I got an error

The ControlID property of the trigger must reference a valid control.

Exception Details:System.InvalidOperationException: The ControlID property of the trigger must reference a valid control.

Can anyone help me? :)

I'm getting the same error when trying to set my triggers to buttons inside of a Gridview. I'm still looking for the answer, but thought I'd post here in case someone came across and knew the answer for both of us.


No one knows why does it happens ?
Did anyone find out how to reference a gridview button in atlas?

for gridview or datagird : you just put an update panel around the grid markup code, hence you don't need to use Triggers to trap event. code like this:

<

atlas:UpdatePanelID="upd1"runat="server"><ContentTemplate>

<asp:GridView ...>...</asp:GridView>

</

ContentTemplate></atlas:UpdatePanel>

Ok, that all. just format your grid as you want, the update panel around the grid will help you control the event from button, hyperlink button... inside the grid and, of course, you don't need to use Triggers here.

Extending idea from those above, if you put the update panel right after the form tag, and so you don't need to trigger any events. Like this:

<form runat="server">
<atlas:UpdatePanel....>
<ContentTemplate>
...your markup code ...
</ContentTemplate>
</UpdatePanel>
</form>


tuantran:

for gridview or datagird : you just put an update panel around the grid markup code, hence you don't need to use Triggers to trap event. code like this:

<

atlas:UpdatePanelID="upd1"runat="server"><ContentTemplate>

<asp:GridView ...>...</asp:GridView>

</

ContentTemplate></atlas:UpdatePanel>

Ok, that all. just format your grid as you want, the update panel around the grid will help you control the event from button, hyperlink button... inside the grid and, of course, you don't need to use Triggers here.

Extending idea from those above, if you put the update panel right after the form tag, and so you don't need to trigger any events. Like this:

<form runat="server">
<atlas:UpdatePanel....>
<ContentTemplate>
...your markup code ...
</ContentTemplate>
</UpdatePanel>
</form>

What if you have more than one update panel? How do I reference the GridView from a separate update panel?


Please copy and paste here the mark-up code of your .aspx in that you have some seperate update panel and brieftly explain your request. I will try to find a correct solution if I can.

Regards

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