Showing posts with label created. Show all posts
Showing posts with label created. Show all posts

Wednesday, March 28, 2012

Link Button as trigger not firing

So I have a link button that is created here...

 LinkButton hide =new LinkButton(); hide.Text ="(hide)"; hide.Click +=new EventHandler(this.hide_Click); hide.ID ="hide" + deviceID;

which is later added to a table cell which is added to a table row which is added to a table. This table is what my function returns (the functions basically builds the table)

From where the function is called I have this code to create a trigger using the linkbutton hide, then add that trigger to the update panel that i am putting the newley created table in...

 AsyncPostBackTrigger trig =new AsyncPostBackTrigger(); ((UpdatePanel)tempTable.Parent.Parent).ContentTemplateContainer.Controls.Add(childTable); trig.ControlID = childTable.Rows[0].Cells[1].Controls[1].UniqueID; trig.EventName ="Click"; ((UpdatePanel)childTable.Parent.Parent).Triggers.Add(trig);

I have tried making the controlID both the unique ID and just the ID and neither work. I know that my just for testing my hide_click function is simple...

private void hide_Click(object sender, EventArgs e) { txtOutput.Text ="IT WORKED!"; }

I know the hide_Click function works because i attached it to other buttons in other tables and it executes fine.

Does anyone know if I am doing something wrong because I cannot seem to figure this out.

Thanks

Hi,

what issue are you experiencing? A full postback instead of an async postback? Or the "IT WORKED!" text isn't displayed? In this case, did you put the Label inside an UpdatePanel?


There is no postback at all. The txtOuput is inside an update panel. It works fine when triggered from other buttons that were added to my page the same way I am adding my link button, but something is acting up. Im not sure if there is a problem with where I am adding the trigger so I am going to try defining the trigger at the same place in code as where I am defining the link button to see if that helps, but i doubt that will change anything.


Ok this is really starting to mess with my head. I have noticed now that when i click on my button, the textbox txtOutput refreshes, but still displays the text that was already there, instead of getting the text from the hide_Click function. This is weird though because when I point other buttons to my hide_Click function, they fire it perfectly and the text box updates. I am confussed


Hi,

Please refer to this:

http://ajax.asp.net/docs/mref/T_System_Web_UI_AsyncPostBackTrigger.aspx

Programmatically adding AsyncPostBackTrigger controls is not supported. Use the RegisterAsyncPostBackControl(Control) method of the ScriptManager control to programmatically register a postback control, and then call the Update() method of the UpdatePanel when the control posts back.

Please try as the above documentation described. If still fails, please post a self-sufficient repro.


great thanks, ill take a look. I was all excited because I was able to programatically add asyncpostback trigers to some update panels, I did this at the time the panels were being created and it worked fine, I guess there are some situations where it just doesnt work though.


so it turns out the trigger is working fine, the only problem is that my hide_Click event isnt being fired. I have had this problem before where having certain settings enabled for different controls cause the controls .click event not to work properly, now its just a matter of finding out what is causing this problem

link usage by ajax framework

HI, I am new using ajax... so..I created a small project with a few controls inside a page.I was doing well every think fine.So I started a web test project to see the impact of using ajax inside my page (link usage)...and what I see was a use of a "library" off size 250Kb ...Is this correct I doing something wrong ?

The controls that I was testing was part off the toolkit

Hi,

According to my understanding, you noticed a .js file with size of 250 KB was downloaded.

This is the correct behavior. Actually, AJAX is implemented with javascript, which will be responsible for sending request asynchronously, update contents on the web form. And there are also a lot auxiliary methods and objects.

So, it's normal to see this.

Just pay attention to changing the debug mode to false in web.config before you are going to deploy your application.


I would like to know if this .js will be downloaded at each post in the page? For navigation between different pages that use Ajax technology .js will be downloaded several times? What I expected is that .js was to be downloaded only once. But my tests don't show this! Am I correct? Or I am loosing something Thank you Very Much

You need to set debug to false in web.config.

linkbuttons in accordionpane header

I am using an accordion that is created dynamically for a menu and have it working as I want - with one exception. When the user clicks on a dynamically created link button on the header, I want to redirect to another page WITHOUT triggering the default action of the accordionpane (expanding or collapsing). Is there any way to accomplish this? Currently, it triggers the default action of the accordionpane (expands or collapses it) then redirects.

Hi,

The expand/collapse action is fired by the <div> element that the header is wrapped in.

When you click in anywhere in the header, it's fired.

When you click on an element in the header, the element's click will be bubbled up to its parent( the header div ) , thus default action is fired too.

So, you can use javascript to prevent the LinkButton to bubble up the event to prevent this from happening.

The following code snippets help to illustrate my idea.

<script type="text/javascript">
function doSomething(e)
{
if (!e) var e = window.event;
e.cancelBubble = true;
if (e.stopPropagation) e.stopPropagation();
}

</script>

<ajaxToolkit:AccordionPane ID="AccordionPane1" runat="server" HeaderCssClass="myclass">
<Header>
<a href="http://links.10026.com/?link=">1. Accordion</a><asp:LinkButton ID="LinkButton2" runat="server">LinkButton</asp:LinkButton>
</Header>

protected void Page_Load(object sender, EventArgs e)
{
LinkButton2.Attributes.Add("onclick", "doSomething();");

}

Hope this helps.

Monday, March 26, 2012

ListSearchExtender error - System.InvalidOperationException: Extender controls may not be

I created a custom web control (ListSearchControl) using the ListBox and ListSearchExtender control. I added this control to another custom control which is dynamically added to a page. The page ahs a ScriptManager tag before any other controls and inside Form tag. The control works fine on page laod, but gives an error on post back - "System.InvalidOperationException: Extender controls may not be registered after PreRender".

I tried using the same custom control((ListSearchControl) adding it to the page directly and it works fine even on postback.

Is there any way to get out of the error in the first case, or is there a known problem with using Control toolkit extenders being added dynamically on the page?

Hi,

Please try the workaround in this thread : http://forums.asp.net/t/1160803.aspx

Nai-Dong Jin - MSFT:

Hi,

From your description, it seems that while you are usingASP.NET AJAX Toolkit with your controls, you'll get a message whichsays "Extender controls may not be registered after PreRender", right?

For this kind of issue, one workaround is to call the baseOnPreRender method before declaring your controls while overriding theOnPreRender method on the page where you had the new extender control.See the following code snippet:

protected override void OnPreRender(EventArgs e)
{
// add base.OnPreRender(e); at the beginning of the method.
base.OnPreRender(e);

// codes to handle with your controls.
...


}

Also, there's a good sample on how to create an ASP.NET AJAX Toolkit Extender Control to Extend an standard control. See,
http://weblogs.asp.net/dwahlin/archive/2007/08/08/creating-an-asp-net-ajax-toolkit-extender-control.aspx

Saturday, March 24, 2012

Load Control. Need Advice.

Hello,

I have a page with a TreeView and a Panel.

I created 10 WebControls which are compiled into a dll library.

My TreeView has 10 nodes. When I click a node I want to show, in the panel, one of the 10 WebControls without refreshing the page.

How can I do this?

Thanks,

Miguel

Hi,

If UpdatePanel is ok for you, the folowing sample is quite similar to what you have described

http://www.couldbedone.com/downloads/DynamicallyCreatedControlsAjax.zip

-yuriy


hello.

here's an old post I've written about that subject:

http://msmvps.com/blogs/luisabreu/archive/2007/02/15/adding-controls-to-an-updatepanel-through-code.aspx

Load Foreign Website into Tab

Hi,

I am using the tabpanel from the AJAX toolkit, and have created multiple tab panels...for each panel I want to load a new site into it...

For example:

Tab 1 -www.asp.net

Tab 2-www.google.com

etc etc...

Does anyone know how I can do this at all?

Thanks

Hi,

You can add iFrames to the different tabs.

More info:

http://www.w3schools.com/tags/tag_iframe.asp

http://msdn2.microsoft.com/en-us/library/ms535258.aspx

Regards


Thanks!

Wednesday, March 21, 2012

Loading image while waiting for web service to deliver image

Hi,

We have share information charts that we get via a third party web service. My problem is that the charts take a while to be created. What I would like to do is have a loading gif while I'm waiting for the image to download.

I am very new to Ajax (just downloaded the bits and pieces to plug into VS2005 this morning), so if anyone could point me in the direction of some script I'd be very thankful.

Thanks

Emilio

Place your charts in an UpdatePanel. Place your loading gif in an UpdateProgress control and associate the two.

http://www.asp.net/ajax/documentation/live/overview/UpdatePanelOverview.aspx

http://www.asp.net/learn/ajax-videos/video-78.aspx (updatepanel)

http://www.asp.net/learn/ajax-videos/video-123.aspx (updateprogress)


Hi,

Thank you for your post!

It seems that you are really a newbie to AJAX,this is a good start point for your learning:ASP.NET AJAX Roadmap

And in my opinion, <ASP.NET AJAX in action> is a decent book to learn ASP.NET AJAX.

If you have further questions ,let me know.

Best Regards,