Reputation: 2053
I have a RadMultipage control on my asp.net web page.
I am loading the user controls as pages inside this control.
Below is the code to load the user controls.
protected void RadMultiPage1_PageViewCreated(object sender, Telerik.Web.UI.RadMultiPageEventArgs e)
{
try
{
string controlName;
int index = e.PageView.ID.Trim().IndexOf(" ");
if (index > 0)
{ controlName = e.PageView.ID.Trim().Remove(index); }
else
{ controlName = e.PageView.ID; }
Control pageViewContents = LoadControl(controlName + ".ascx");
pageViewContents.ID = e.PageView.ID + "userControl";
e.PageView.Controls.Add(pageViewContents);
}
catch (Exception ex)
{
Utility.WalkException(this, ex, "There was an error while performing this operation.");
}
}
I have also enabled the view state and autoeventwireup.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" EnableViewState="true" ViewStateMode="Enabled" Inherits="VentureAssessmentApp.Default" %>
Now the problem I am having is with the button on the user control. The click event of that button is not getting fired. It just reloads the page. Even the IsPostBack is returning false.
Can any one suggest some solution ? It happens that some times the click event works and most of the time it doesn't work.
Upvotes: 3
Views: 1108
Reputation: 2053
Finally i found the issue. Please go through This Answer. This was exactly what was happening in my solution.
ASP.NET 4 now renders the HTML form element’s action attribute value as an empty string when a request is made to an extensionless URL that has a default document mapped to it. For example, in earlier releases of ASP.NET, a request to http://contoso.com would result in a request to Default.aspx. In that document, the opening form tag would be rendered as in the following example:
In ASP.NET 4, a request to http://contoso.com also results in a request to Default.aspx. However, ASP.NET now renders the HTML opening form tag as in the following example:
This difference in how the action attribute is rendered can cause subtle changes in how a form post is processed by IIS and ASP.NET. When the action attribute is an empty string, the IIS DefaultDocumentModule object will create a child request to Default.aspx. Under most conditions, this child request is transparent to application code, and the Default.aspx page runs normally.
However, a potential interaction between managed code and IIS 7 or IIS 7.5 Integrated mode can cause managed .aspx pages to stop working properly during the child request.
Add this to global.ascx to fix the issue.
void Application_BeginRequest(object sender, EventArgs e)
{
var app = (HttpApplication)sender;
if (app.Context.Request.Url.LocalPath.EndsWith("/"))
{
app.Context.RewritePath(
string.Concat(app.Context.Request.Url.LocalPath, "default.aspx"));
}
}
Hope this will be helpful.
Thanks.
Upvotes: 0
Reputation: 14830
This is a typical page life cycle issue. I'm guessing that what's happening is that when the postback is triggered, the page has no clue about which control triggered the postback because when it does the evaluation the Button (and its parent UserControl) haven't been added to the page's control hierarchy...so, I'd point my finger to the RadMultiPage1_PageViewCreated
event handler. It looks to me like an awkward place to dynamically add server controls to a page.
Move the control loading logic out of the RadMultiPage1_PageViewCreated
event. Place this logic in the Page's Init
event, or on the page's Load
event if the Init
event is too early.
You can determine what page has been selected in the RadMultiPage
control by inspecting the SelectedIndex
property or the SelectedPageView
property. However, if you are using a RadTabStrip
control in conjunction with the RadMultiPage
control you can inspect the RadTabStrip
's SelectedTab
or SelectedIndex
property
protected override void OnLoad(EventArgs e)
{
LoadStuff();
}
private void LoadStuff()
{
try
{
string controlName;
int index = YOUR_MULTI_PAGE_CONTROL.SelectedIndex;
if (index > 0)
{ controlName = YOUR_MULTI_PAGE_CONTROL.PageViews[index].ID.Trim().Remove(index); }
else
{ controlName = YOUR_MULTI_PAGE_CONTROL.PageViews[index].ID; }
Control pageViewContents = LoadControl(controlName + ".ascx");
pageViewContents.ID = YOUR_MULTI_PAGE_CONTROL.PageViews[index].ID + "userControl";
YOUR_MULTI_PAGE_CONTROL.PageView.Controls.Add(pageViewContents);
}
catch (Exception ex)
{
Utility.WalkException(this, ex, "There was an error while performing this operation.");
}
}
Upvotes: 1