Issue with getting control id when tabcontainer is used - asp.net

I have an AJAX Control Toolkit TabContainer in my ASP.NET page. In one of the tabs in the TabContainer, there is a GridView. Now, I have an UpdatePanel for which I want to give trigger as "RowCommand" of GridView mentioned above. The UpdatePanel is outside the TabContainer. But when I give the GridView id, I am getting the error:
A control with ID 'grvSummary' could not be found for the trigger in UpdatePanel 'updSegment'.
Trigger markup:
<asp:AsyncPostBackTrigger ControlID="grvSummary" EventName="RowCommand" />

You will have to programmatically add the trigger to your UpdatePanel. This is because your GridView may or may not start in a different ContentPlaceHolder than the UpdatePanel (namely, the <ContentTemplate> of your TabContainer). Like this (note that this really needs to be done in Page_Init, due to the Page Life Cycle):
protected void Page_Init(object sender, EventArgs e)
{
AsyncPostBackTrigger trig = new AsyncPostBackTrigger();
trig.ControlID = grvSummary.UniqueID;
trig.EventName = "RowCommand";
updSegment.Triggers.Add(trig);
}
It looks like this may be a problem with ASP.NET / AJAX assuming the wrong Control.UniqueID value for the Control being used as a trigger.
Source: Triggering an UpdatePanel in a different ContentPlaceHolder

Related

UpdatePanel with dynamic controls won't postback

I am using UpdatePanel and loading dynamically the content:
<asp:UpdatePanel runat="server" ID="updatePanel" UpdateMode="Conditional">
<ContentTemplate>
<div id="dashboard-main">
<div id="dashboard-content">
<div class="d-content">
<asp:PlaceHolder runat="server" ID="ContentPanel">
</asp:PlaceHolder>
</div>
</div>
<div id="sub-content">
<ul id="nav-02">
<li class="current">
<asp:LinkButton CommandArgument="Stuff" OnClick="LoadMiniDash" runat="server" ID="myStuff">
My Stuff</asp:LinkButton></li>....
What I do is once the LinkButton is pressed, I load a control to the ContentTemplate:
protected void LoadMiniDash(object sender, EventArgs e)
{
string miniDashName = ((LinkButton)sender).CommandArgument;
Control control = Page.LoadControl("~/controls/Dashboard" + miniDashName + ".ascx");
ContentPanel.Controls.Clear();
ContentPanel.Controls.Add(control);
updatePanel.Update();
}
My problem is, that inside this newly loaded control, there is another Button. once clicked, the updatepanel gets emptied and not postback to the control is made. (it does however do a post to the page itself async. but i see the control won't reach its own code once clicked).
what can be the problem?
thanks
I just tried to rewrite your question. When you load your userControl it appears in the updatePanel. When you hit the button in the userControl, your updatePanel gets updated - and your userControl "disappears".
Imo it disappears because you do not reload your userControl. I tried the following snippet:
protected void btnLoadControl_Click(object sender, EventArgs e)
{
/// save the name of the userControl to load in a SessionVar
Session["userControl2Load"] = "ucDemo.ascx";
Control control = LoadControl("ucDemo.ascx");
phDemo.Controls.Clear();
phDemo.Controls.Add(control);
upDemo.Update();
}
/// reload your userControl on every init of the updatePanel
/// when the sessionVar is set
protected void upDemo_Init(object sender, EventArgs e)
{
if (Session["userControl2Load"] != null)
{
string controlName = Session["userControl2Load"].ToString();
Control control = LoadControl(controlName);
phDemo.Controls.Clear();
phDemo.Controls.Add(control);
}
Debug.WriteLine("upDemo Init");
}
it worked for me. Let me know if it work for you too. hth
I have faced similar issue.. and you know solution to this problem is very simple..
Logic is .. If you have one or more update panel in the same page then properties of all update panel should be same such as
Update Mode : Always
EnableViewState : true(if you are using it)
For example you have 3 update panel in the same asp.net ajax page with following id
UpdatePanel1
UpdatePanel2
UpdatePanel3
In the Update Panel 1 (UpdatePanel1) you have a button which specific a record from the gridview. On the click on the button in the update panel1, FormView in the UpdatePanel2 should display the corresponding values.
To achieve this, you need to specific Update Panel Properties of (UpdatePanel1, UpdatePanel2) as
ChildrenAsTrigger : True
EnableViewState : true
RenderMode : Block/Inline
UpdateMode : Always
Visible : true
Doing above activity values in the UpdatePanel3 is changed or you can say it's not depending on the UpdatePanel1 or UpdatePanel2
If you find it useful, please mark it as your answer else let me know...

Adding or attaching an OnItemCommand Event handler to ASP.NET CheckBox

I wonder if it is possible to add or attach or extend the asp.net checkbox in a way to add OnCommand , CommandName, CommandArgument functionality.
In brief I want to add to a asp. net CheckBox the OnCommand functionality like Button or LinkButton has.
I want to place a check box in a Repeater ItemTemplate and want to handle on checkbox clicks in OnItemCommand handler.
I solved my problem using a simple trick. I created a web user control using a checkbox and invisible link button.
<asp:CheckBox ID="cbSelector" runat="server" AutoPostBack="true" />
<asp:LinkButton ID="btnHiddenCheckBox" runat="server" Visible="false" CommandName="Select"></asp:LinkButton>
in the code behind i added some event handlers ...
protected void Page_Load(object sender, EventArgs e)
{
cbSelector.CheckedChanged += new EventHandler(cbSelector_CheckedChanged);
}
void cbSelector_CheckedChanged(object sender, EventArgs e)
{
btnHiddenCheckBox.CommandName = "Select";
btnHiddenCheckBox.CommandArgument = Convert.ToString(cbSelector.Checked);
((IPostBackEventHandler)btnHiddenCheckBox).RaisePostBackEvent(null);
}
and programmatically raised a Click event with parameters and it works.
Patrik I am going to suggest you something completely different, use JQuery and get this done via Ajax so to give the users way smoother experience.
there is a nice article with a step by step here: ASP.Net CheckBox and JQuery
everything is better than a CheckBox or a Button with AutoPostBack set to true nowadays in year 2011, 2012 soon ;-)
The same could be achieved using OnCheckChanged event.
You can find out what the RepeaterItem is to be able to access controls in the same RepeaterItem
ALternatively, see this SO question for a solution on how to use OnItemCommand for CheckBox:
Checkbox OnClick/ItemCommand in Repeater or DataList

ASPxGridView PerformCallback() does full page postback

I have a checkbox that when clicked, calls a javascript program that calls grid.PerformCallback(), where grid is the client instance name of my ASPxGridView gridview. This gridview also has a custom callback method which databinds the table. However when i click my checkbox, instead of only performing callback on the gridview, my page does a full postback, which posts the form. How do i make it so that it only updates the gridview?
function toggle()
{
productGrid.PerformCallback();
}//end toggleExch()
<dx:ASPxGridView ClientInstanceName="productGrid" Width="100%" ID="productGrid" runat="server"
DataSourceID="ProductSQL" EnableCallBacks="true" OnCustomCallback="productGrid_OnCustomCallback">
</dx:ASPxGridView>
protected void productGrid_OnCustomCallback(object sender,
DevExpress.Web.ASPxGridView.ASPxGridViewCustomCallbackEventArgs e)
{
System.Diagnostics.Debug.WriteLine("in postback");
productGrid.DataBind();
}//end productGrid_OnCustomCallback()
so basically the debug line is not printed and the page goes into full postback - how do i only postback and databind the grid? (i need to do more server side processing before databinding or directly binding from jquery is out of the question)
found the answer - should use iscallback instead of ispostback
Unfortunately, you did not post the aspx markup of the button. However, if this is the ASPxButton, make certain that its AutoPostback property is false ...

control with ID 'GridView1' could not be found for the trigger in UpdatePanel 'UpdatePanel1'

I have two gridview in update panel and m adding entries from one gridview to another on selectedIndexChanged event what m trying to do is updating update panel on this event selectedindexchanged ...but my gridview is inside accordian control so it does not get initialized and hence i get this error .....
control with ID 'GridView1' could not be found for the trigger in UpdatePanel 'UpdatePanel1'
Anybody knows solution?
I haven't had a chance to test this yet, but this might be what you're looking for. It's possible that you need to dynamically add the trigger at Page_Init. Like this:
protected void Page_Init()
{
AsyncPostBackTrigger trigger = new AsyncPostBackTrigger();
trigger.EventName = "SelectedIndexChanged";
trigger.ControlID = GridView1.UniqueID.ToString();
UpdatePanel1.Triggers.Add(trigger);
}
Try adding that to your code-behind contemporary to Page_Load() and removing the trigger from your mark-up.

How can I update an UpdatePanel in a control from the page?

I have a modal on a page that also contains a user control.
When clicking the 'OK' button in the modal, I would like to update an UpdatePanel that is contained within the user control on the page.
Currently the 'OK' button on the modal does a full page postback, I'd like to just update the panel, but I'm not sure how to add it as a trigger since it's not in the control the UpdatePanel is.
Thanks.
I have a partial answer... I can update the panel once by doing this:
Dim addTrigger As New AsyncPostBackTrigger
addTrigger.ControlID = MyButton.ID
addTrigger.EventName = "Click"
MyUserControl.GetUpdatePanel.Triggers.Add(addTrigger)
This will cause a partial post-back the first time, but after that first time it causes an entire page reload. Any ideas?
You can explicitly add the OK button as a AsyncPostBackTrigger for the UpdatePanel.
In the aspx markup for the UpdatePanel:
<asp:UpdatePanel ID="updPanel" runat="server">
<ContentTemplate>
....
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="the control" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
or in the code-behind:
protected override void OnInit(EventArgs e)
{
AsyncPostBackTrigger trigger = new AsyncPostBackTrigger();
trigger.ControlID = "the Control";
trigger.EventName = "Click";
updPanel.Triggers.Add(trigger);
base.OnInit(e);
}
Maybe I am missing some subtlety here, but can't you just call the Update() method on the Update Panel?
You can use the following pattern to control a panel postback in JavaScript:
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm._panelsToRefreshIDs = UPComments.uniqueID;
prm._doPostBack(eventTarget,eventArgument);
theForm.submit();
Can't you just add an AsyncPostBackTrigger programmatically from the code-behind?
Like This ?
just put the contents of the Panel in an update panel sothat you have:
Your user control here.
this will also prevent the popup from disapearing until you want it to.
In your code behind you can then call it with popup.show(0 or pop.hide() and link these to your user control by addin gan event ot it and handling it inyour pages code behind. this way your user control can direct the popup what to do and when. you can even for it to update hte update panel if you needed for some reason.
for the case above tha tI just realized is tha tyou wan to updat ehte panel in the control. Create a method i nthe control that calls the update method o teh update panel an dthen fire that event from your page. It's the same principal in reverse. By utilizing event well you can wire up your application to do some pretty cool stuff.

Resources