Showing posts with label button. Show all posts
Showing posts with label button. 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 button inside update panel causes post back

I have a linkbutton inside the update panel. I registered it with AsyncPostBackTrigger, but when I click that link button, the whole page is refreshed instead of that update panel, what could I have gone wrong?

Check the EnablePartialRendering="true" of ScriptManager is et or not ?

Also check UpdateMode="Conditional" of UpdatePanel is set or not ?

Linkbuttons in a TabContainer lose the active tab

Hi, I have a tabcontainer with a couple of panels. If I have a Button in each panel then clicking the button posts the page back and the tab panel I was in remains active/visible. BUT if I put a link button in Panel 2 and click that then the tabcontainer resets to the first panel.

Here is a simple example:

<cc1:TabContainer ID="TabContainer1" runat="server">
<cc1:TabPanel ID="TabPanel1" runat="server" HeaderText="tab 1">
<ContentTemplate>
<asp:Button runat="server" ID="Button1" Text="postback 1" />
</ContentTemplate>
</cc1:TabPanel>
<cc1:TabPanel ID="TabPanel2" runat="server" HeaderText="tab 2"> <ContentTemplate>

<asp:LinkButton runat=server ID=lnk1>postback from panel 2</asp:LinkButton>
</ContentTemplate>
</cc1:TabPanel>
</cc1:TabContainer>

If I put a button in panel 2 as well as the linkbutton then I get the same thing, BUT if I click the Button first then clicking the link button does not cause the tabcontainer to reset. Which seems to suggest that AJAX is using a button event in some way, but not a linkbutton.

This is causing me a major headache as I have already designed the UI and coded all the DB and middle-tier code, wiring the UI up was supposed to be the easy bit!Wink

Hoping someone can help

Andrew

This problem has been logged with the AJAX Control Toolkit developers as an issue and a workaround is detailed here:http://forums.asp.net/thread/1550723.aspx (basically wrap the tabcontainer in an update panel so that the non-Button postbacks get routed through the AJAX async handlers)

Monday, March 26, 2012

ListBox does not preserve selected items after using UpdatePanel

Hi there,

I have a ListBox with Multiple Selection feature. After I click the Button on the form, I should process the selected items in the ListBox. The code works fine but after I add the ListBox in an UpdatePanel, it does not preserve selected items.

Any suggestions?

Thanks,
Mosh

use hidden fields.
function addItemstoHiddenField(){
var lbPlantDest = document.getElementById("lbPlantDest");
var lbSalesDest = document.getElementById("lbSalesDest");
var lbPlantDest = document.getElementById("lbPlantSrc");
var lbSalesDest = document.getElementById("lbSalesSrc");
var hdnPlantAccess = document.getElementById('hdnPlantAccess');
var hdnSalesAccess = document.getElementById('hdnSalesAccess');
var hdnPlantAccess = document.getElementById('hdnSrcPlantAccess');
var hdnSalesAccess = document.getElementById('hdnSrcSalesAccess');
for (i = lbPlantDest.options.length - 1; i >= 0; i--) {
hdnPlantAccess.value = hdnPlantAccess.value + lbPlantDest.options[i].value + ',';
}
for (i = lbSalesDest.options.length - 1; i >= 0; i--) {
hdnSalesAccess.value = hdnSalesAccess.value + lbSalesDest.options[i].value + ',';
}
for (i = lbPlantSrc.options.length - 1; i >= 0; i--) {
hdnSrcPlantAccess.value = hdnSrcPlantAccess.value + lbPlantSrc.options[i].value + ',';
}
for (i = lbSalesSrc.options.length - 1; i >= 0; i--) {
hdnSrcSalesAccess.value = hdnSrcSalesAccess.value + lbSalesSrc.options[i].value + ',';
}
}

Saturday, March 24, 2012

Load a javascript file in an updatepanel

Ipresent the context to you. I have a project principal compound of anupdatepanel. When I click on a button, I filled my updatepanel with a"templatd control". This one appears well. This control haves embeddes resources (images + Javascript file). My problem is that my control charges only the images and not my Javascript file. When I use this control in a simple page, it works correctly. I think that it is impossible to charge a fileJavascript in a updatepanel. What do you think about it? Thank you inadvance for your answers.

Damien

Damien,

Personally what I would do as UpdatePanel makes a server request to do your processing in the postback server side, easier and cleaner, you already in the server, then why not. Putting javascript with the UpdatePanel, why? the UpdatePanel is to go to the server without the user to see the request, then just use that!

Makes sense?

Load ascx in other Page using Ajax

I have one application, which has one Home.aspx, Head.Ascx and Footer.Ascx, Head.aspx has two button, And all controls of head.ascx and footer.ascx in ajax panel, now in home page when i click on one button then i want to load head.ascx in my Home page and if i click on second button then i want to load footer.aspx in Home page and unload Head.ascx. I am using ajax in my application. But not enable to solve this.

Thanks

Hi,

Here is an example made according to your requirement:

<%@. Page Language="C#" %><!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 btnHeader_Click(object sender, EventArgs e) { ViewState["show"] = "h"; } protected void btnFooter_Click(object sender, EventArgs e) { ViewState["show"] = "f"; } protected void Page_PreRender(object sender, EventArgs e) { if (ViewState["show"] != null) { string show = ViewState["show"].ToString(); if (show == "h") { Control ctrl = this.LoadControl("Header.ascx"); PlaceHolder1.Controls.Add(ctrl); } else { Control ctrl = this.LoadControl("Footer.ascx"); PlaceHolder1.Controls.Add(ctrl); } } }</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> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:Button ID="btnHeader" runat="server" Text="Show Header" onclick="btnHeader_Click" /> <asp:Button ID="btnFooter" runat="server" Text="Show Footer" onclick="btnFooter_Click" /> <asp:Button ID="Button3" runat="server" Text="Another Button" /> <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder> </ContentTemplate> </asp:UpdatePanel> </div> </form></body></html>

Thanks Raymond Wen , it solved

Wednesday, March 21, 2012

loading page and click in any button

I am facing this problem lot , when page is downloading content and in between this user click on any link then we got error page.

and this error details insert in the database

System.Threading.ThreadAbortException: Thread was being aborted.
at System.Threading.Thread.AbortInternal()
at System.Threading.Thread.Abort(Object stateInfo)
at System.Web.HttpResponse.End()
at System.Web.HttpResponse.Redirect(String url, Boolean endResponse)
at System.Web.HttpResponse.Redirect(String url)
at framework_GacStore_OrderList.GetGACOrderList()
at framework_GacStore_OrderList.Page_Load(Object sender, EventArgs e)


Would you mind posting the code?


Hi pawan_mca03

I am afraid we cannot find out the exact root cause without further information .So I suggest that you'd better share your source code here. If your problem has been resolved , Sharing your work will be greatly appreciated.

Localization

Hello,

I am working on a web site which is using localization features since it will uses various languages.

I have a button to switch from one language to another. I am converting it to AJAX.

Usually I have a class from which every page inherits so when the language it is changed the page is refresh and that class changes culture (see the class at the end of this post)

Now, by using AJAX I suppose all I need to do is to place all the localized content inside Update Panels so when I switch language those panels content will be updated with the new culture. right?

This is confusing me.


Thanks,

Miguel

' Config
Public Class Config
Inherits Page

' Culture | Initialize Culture
Protected Overrides Sub InitializeCulture()

' Call base class implementation
MyBase.InitializeCulture()

' Get culture from profile
Dim culture As String = CType(Context.Profile, ProfileCommon).Settings.Culture

' Check if user has requested specific culture
If (culture IsNot Nothing) AndAlso (culture <> "Auto") Then

' Assign culture UI
MyBase.UICulture = culture

' Assign culture with region
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(culture)

End If

End Sub ' InitializeCulture

End Class ' Config

Try to take a look at this reading about Ajax & Localization -http://blog.languagetranslation.com/public/item/126228