Showing posts with label fire. Show all posts
Showing posts with label fire. Show all posts

Wednesday, March 28, 2012

Dynamic controls and Updatepanel

Hi,

First time poster here. (waves)

Here is my problem: Dynamically created LinkButtons within an Updatepanel don't seem to fire their Commands.
I have a few LinkButtons that are dynamically created within an UpdatePanel based on the contents of a TextBox. Everything renders as it should, only when I click on one of the LinkButtons, nothing happens. When I Debug, it the function the LinkButtons refer to (trough Command) never fires up. I suspect that this has something to do with the fact that CommandEventHandler is never actually registered because of the partial update. Is this correct? What are my options in this situation?

hello.

can you show us the code?


This is the code that is being used to generate the buttons:
foreach (XmlNode rowin rows){ LinkButton klantLink =new LinkButton(); klantLink.Text = row["NAME"].InnerText +", " + row["FIRSTNAME"].InnerText; klantLink.CommandArgument = row["K_CONTACT"].InnerText; klantLink.Command +=new CommandEventHandler(gezochteKlant_Click); searchDiv.Controls.Add(klantLink); searchDiv.Controls.Add(new LiteralControl("<br />") );}
searchDiv.Visible = true;
searchPanel.Update();
And this is the location in the html where the content is added:
<atlas:UpdatePanel ID="searchPanel" runat="server" Mode="Conditional"> <ContentTemplate> <div runat="server" id="searchDiv" visible="false"> </div> </ContentTemplate></atlas:UpdatePanel>

hello again.

question: where are you adding the controls, ie, in which event?


They are added trough the OnTextChanged of a textbox.

hello.

hum, not sure about what's happening.

i've built a small sample that adds a button during the load event and this works ok:

<%@. 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 override void OnLoad(EventArgs e)
{
base.OnLoad(e);

LinkButton klantLink = new LinkButton();
klantLink.Text = "hello";
klantLink.CommandArgument = "test";
klantLink.Command += new CommandEventHandler(gezochteKlant_Click);

searchDiv.Controls.Add(klantLink);
searchDiv.Controls.Add(new LiteralControl("<br />"));

}

void gezochteKlant_Click(object sender, EventArgs args)
{
txt.Text = DateTime.Now.ToString();
}
</script>

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

<atlas:UpdatePanel runat="server" id="panel">
<ContentTemplate>
<div runat="server" id="searchDiv" />
<asp:TextBox runat="server" id="txt" />
</ContentTemplate>
</atlas:UpdatePanel>
<hr />
<%= DateTime.Now.ToString() %>
</div>
</form>
</body>
</html>

maybe the problem is that you're only creating the button during the textchanged event; a click will fire another postback, but you won't the buttons won't be created since the text didn't change and this will not fire your event.


Thanks for the reply. I think the problem is that I create the controls directly in the function linked to the ontextchanged event.

hello.

that's what i was trynig to say. since you add them on the textchanged event, you must also add them on future postbacks or else the button will not exist. so, what i suggest is adding some sort of flag that will let you add the buttons during the load event of a postback operation.


Hi,

I am very badly stuck up at something.

I am also dynamically loading my user control in the Update panel. My User Control act as a ModalPopUp Extender. So what i am doing is , on the click on the button on my page I am showing a Modal PopUp which is a User Control with some buttons and a grid. Which is being loaded on some values passed from the Page. So what I have done is I am adding Dynamically that user Control on the Click event of the button on my Page.But when I click any button my User Control , the event associated with that button does not get fired. It just unloades the usecontrol and event related to the buttons on the User control are getting fired.. Please help and look into this matter..

The Code:

protectedvoid btnAddContent_Click(object sender,EventArgs e)

{

//AddContent1 is my User Control with ProposalID and SectionID are the Properties.. Place Holder is on my Page where I am placing my control.

AddContent

AddContent1 = (AddContent)Page.LoadControl("AddContent.ascx");

AddContent1.ProposalID = 44;

AddContent1.SectionID = 1;

PlaceHolderTest.Controls.Add(AddContent1);

Label lblAdd = (Label)(AddContent1.FindControl("lblAdd"));

lblAdd.Text =

"Add Content";Label lblSecQues = (Label)(AddContent1.FindControl("lblSecQues"));

lblSecQues.Text =

"Section:";

mpeAddContent.Show();

}

Thanks in Avance

Abhishek

Saturday, March 24, 2012

DropDownLists OnSelectedIndexChanged wont fire

Here what I do

<atlas:UpdatePanel ID="mypanel" mode="always" runat="server">
<ContentTemplate>
<asp:DropDownList ID="mylist" runat="server"
DataSource="mydatasource"
DataTextField="mytext"
DataValueField="myvalue"
OnSelectedIndexChanged="mylist_SelectedIndexChanged" />
<asp:Label ID="mylabel" runat="server" />
<asp:TextBox ID="mytextbox" runat="server" />
</ContentTemplate>
<Triggers>
<atlas:ControlEventTrigger controlID="mylist"
event="SelectedIndexChanged" />
</Triggers>
</atlas:UpdatePanel>

the logic is simple, when the selected item inside the DropDownList changed, it will change the value of the textbox. inside mylist_SelectedIndexChanged method in the codebehind file is just simple putting a value using mytextbox.Text = "something";

But unfortunatelly, when I click on the DropDownList, change it's selected item, nothing happend. The value of the textbox also didn't change.

Do I do something wrong here? or miss something? Please advise.


Thanks,

Lok

As far as I can see all you need to do is set theAutoPostBack="true"in the DropDownList. Works just fine for me that way.

Greetz,
Zentral


Hi Zentral,

Thanks for the reply.

But, it's true, that giving AutoPostBack="true" will not makes all the page portion refreshed? not just only the UpdatePanel portion?

Or because of the control inside an UpdatePanel, so all the postback action happened only affected particular UpdatePanel.

Regards,

Lok


Hey Lok,

That's correct, due to the fact that the DropDownList is nested within an UpdatePanel, only the data within the panel will be considered for the postback. In this case you can look at the UpdatePanel as a "page scope limiter". Thus only the content within the UpdatePanel will be re-rendered.

You can test this easily for example by placing a label inside the UpdatePanel and placing a different label outside the UpdatePanel. Place your DropDownList inside the UpdatePanel and set the AutoPostBack="true", implement the server event and within that event set both labels (the one inside the updatepanel and the one outside) to the same value. You will notice that only the label inside the UpdatePanel will have its value updated while the one outside will remain unchanged.

Greetz!
Zentral

DropDownList SelectedIndexChanged not fire (Autopostback - true!)

1<asp:DropDownList ID="SectionsDDL" runat="server" DataSourceID="SectionsObDS"2AutoPostBack="True" OnSelectedIndexChanged="SectionsDDL_SelectedIndexChanged"3DataTextField="titleName" DataValueField="id">4</asp:DropDownList>56<asp:UpdatePanel ID="UpdatePanel1" runat="server">7<ContentTemplate>8<asp:Panel ID="sectData" runat="server">9<asp:Label ID="tstlbl" runat="server" />10</asp:Panel>11</ContentTemplate>12<Triggers>13<asp:AsyncPostBackTrigger ControlID="sectionsDDL" EventName="SelectedIndexChanged" />14</Triggers>15</asp:UpdatePanel>

Everything is ok when I choose any item in DDL but first. When I choose first SelectedIndexChanged not fire.

I tried to find answer on forum and could not.

it sounds like your first item is selected when the dropdown loads so if you pick that answer the selected index never changes. Try adding an additional item called Not Selected or choos one or something along those lines as the first item in the list then everytime you should postback.

AjaxButter


Or you could change the SelectedIndex property to -1

Wednesday, March 21, 2012

DropDownExtender cannot work correctly in IE6 and Firefox 2.0. Theme cannot change in Fire

Hi there,
A week later, I begin develop a new shop cart application with Ajax enabled.
My problem is:
1. My Page option feature (to change site's theme) is put in a panel with a DropDownExtender.
It cannot show/hide correctly:
- In Internet Explorer 6.0, italway show a "area" at top or bottom in the page.
Click on darkblue and pink icon still can change page skin.
- In Firefox browser, my application hide/show "area" correctly. But, when click on any icon
(an asp:ImageButton), after a postback,page's theme doesn't change.
- In Opera, and IE 7, everything is fine.

Please help me.
This is my demo site url:
http://ajaxshop-1.at.vwdhosting.net/
"Page option" in my language is: "Tùy ch?n trang" - under the search bar.

My source code:

1/*2* This is my user control aspx code3*/4"C#" AutoEventWireup="true" CodeFile="SelectTheme.ascx.cs" Inherits="UserControls_SelectTheme" %>5"AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>6

"right">7

class="PageOptionTextStyle">8 "HyperLinkPageOption" runat="server" Text="Tùy ch?n trang "9 Width="100px">10 "DropDownExtender1" runat="server" DropDownControlID="PanelPageOption"11 TargetControlID="HyperLinkPageOption" HighlightBorderColor="transparent" >1213 "PanelPageOption" runat="server" Width="100px">14

"vertical-align:middle;text-align:center; background-color:LightYellow; height:20px; border-right: gray 1px ridge; border-top: gray 1px ridge; border-left: gray 1px ridge; border-bottom: gray 1px ridge;" align="left">15

16"middle" height="20px">17"middle">18class="innerlink"> Màu s?c: 19"ImageButtonDarkBlueSeclect" runat="server" SkinID="DarkblueSkinSelectButton" OnClick="ImageButtonDarkBlueSeclect_Click">20 21"ImageButtonDarkRedSelect" runat="server" SkinID="DarkredSkinSelectButton" OnClick="ImageButtonDarkRedSelect_Click">222324

2526

2728

29

303132/*33* This is code behind34*/35public partialclass UserControls_SelectTheme : System.Web.UI.UserControl36{37protected void Page_Load(object sender, EventArgs e)38 {3940 }41protected void ImageButtonDarkBlueSeclect_Click(object sender, ImageClickEventArgs e)42 {43 MySetTheme("Darkblue");44 }45protected void ImageButtonDarkRedSelect_Click(object sender, ImageClickEventArgs e)46 {47 MySetTheme("Darkred");48 }4950protected void MySetTheme(string themename)51 {52//Apply new theme53 Profile.CurrentTheme = themename;5455//Transfer to previous page56 Server.Transfer(Page.AppRelativeVirtualPath.ToString());57 }58}5960

Sorry, y writing "A week later, I begin developing a new shop cart application with Ajax enabled.
" i mean "A week before, I began develop a new shop cart application with Ajax enabled"

And, if you don't want to check my error in my web page, you can view this image

Error in IE6