.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Replace control postback processing in ASP.NET MVC

Posted By:      Posted Date: September 16, 2010    Points: 0   Category :ASP.Net
I've developed a Web User Control with ASP.NET Web Foms that uses client side binding and allows to the user to enter a series of items. During a post, the JavaScript code of my control serializes the items in JSON and put them in a hidden field so the server code of the control can take this JSON string, deserialize it and expose the entered items through a property . How can I obtain a similar functionality and reusability with MVC since during a post my control won't be there to take this JSON string and interpret it correctly? In the end, the hidden field "trick" and the specifics of what data is serialized (and in what way) is just part of the internals of my control that shouldn't have to care to "anyone" outside it (after all, that's why the component abstraction exists). (Sorry about my English)

View Complete Post

More Related Resource Links

Dynamically load user control without postback


Hi all,

I need urgent help. (c#coding)

In my base page, I have a dropdownlist control which loads different usercontrols on selectedindexchanged event.

While loading these usercontrols, my page postbacks all the page. I used updatepanel but again same problem.

Is there any way to load controls without postback? I Really need help as soon as possible.

Here is my code:

protected void Page_Init(object sender, EventArgs e)
        if (Session["control"] != null)
            string c = Session["control"].ToString();
            if (c == "1")
                iuc = (IlkogretimUC)LoadControl("~/Controls/Ilkogretim.ascx");
                dl.SelectedValue = Session["control"].ToString();
            else if (c == "2")
                luc = (LiseUC)LoadControl("~/Controls/LiseUC.ascx");
                dl.SelectedValue = Session["control"].ToString();
            else if (c == "3")
                youc = (YuksekokulUC)LoadControl("~/Controls/Yuksekokul.ascx");

Get content of programatically created control before postback

Hi.I have quite a problem here, and hope you can help :)I´ll try to describe the problem in steps, as this might be the easiest to understand:1. Page_Load is called when the page is requested, and calls a BuildTable() method2. The BuildTable method creates a table which contains several textboxes3. the user types some text in these textboxes4. The userthen  changes an item in a Dropdownlist on the page which is intended to change some other content on the page5. Page_Load is called, and afterwards the DropDownListBookingType_SelectedIndexChanged(object sender,EventArgs e) method are called, and the content is changed6. The text the user typed in the programmatically created textbox controls are lost!Now how do I remain this text information? If just the SelectedIndex_changed method was called first, I could save it in session.. But as far as I can tell, all data on the page are discarded when you create a partial postback :(What to do?Thanks alot for your time!

Client Javascript runs, but then page errors out when clicking on a control that uses postback

Using this script on a button click <script language="javascript"> function printdiv(printpage) { var headstr = "<html><head><title></title></head><body>"; var footstr = "</body>"; var newstr = document.all.item(printpage).innerHTML; var oldstr = document.body.innerHTML; document.body.innerHTML = headstr + newstr + footstr; window.print(); document.body.innerHTML = oldstr; return false; } </script> After it is done, I can't click on my calendar control.  I was hoping to add somethign that would force a refresh in the script, but nothing I do works. Any thoughts?  Thanks! 

FileUpload control loses value on postback.

I'm having a little problem with my file uploading. Does anybody know how to maintain the value in the FileUpload control between server posts?I have a form which, among other things, uploads a file. I am using an FileUpload control (created dynamically) to let a user browse their PC for a file and then using the SaveAs method to upload the file to the server.When I'm selecting a file and Click on Next button for processing then selected file is lost.Same is happening with me with HtmlTextArea (dynamically generated) , the problem was that I was not again re-initializing the controls after postback. What I did is re-initialized it in Init method of placeholder (as I have created/placed all dynamic controls in placeholder ).But this thing is not working for fileupload control. I found solution in one of the forum is that "use hiddenField Control to transfer the selected file from the client to server"but this mechanism will only help to retain the name of file in a hidden variable and the FileUpload1.PostedFile.SaveAs(filename) will not work bcz of absense of object (fileupload1).here is code:protected void lnkbtnNext_Click(object sender, EventArgs e) { if (Session["pnl"].ToString() == "0") { /* other stuff code */ } else if (Session["pnl"].ToString() == "1")

get disable control values during postback

 Hi, I have a page it contains some criteria part based on criteria click upon generate button data will displayed on gird page also contains modify button where user can modify the grid data once user clicks modify button the selected criteria part will disable everything works as expected.. but i am not getting the disable control values during postback how to get the values during postback?   Thanks Maverick  

how can i replace a file from a directory using file upload control and c# in a web applicatin

i m developing a web based appllication with asp.net and c#. I want to replace a file that is in a directory by code.

unable to trace value after postback within Custom Server Control

public class TextBox : AStateManagement, IControl { #region "Variables" #region "Local Variables" protected System.Web.UI.WebControls.WebControl _TextBox = null; protected string _CssClass = string.Empty; protected string _Text = string.Empty; protected bool _Visible = true; protected bool _Enabled = true; protected string _ID = string.Empty; protected bool _IsViewStateLoaded = false; #endregion "Local Variables" #region "Global Variables" #endregion "Global Variables" #endregion "Variable" #region "Constructor" public TextBox() { _TextBox = new System.Web.UI.WebControls.TextBox(); _TextBox.ID = this.UniqueID; } #endregion "Constructor" #region "Events" #endregion "Events" #region "Disposable" #endregion "Disposable" #region "Properties" public override string CssClass { get { return _CssClass; } set { _TextBox.CssClass = _CssClass = value; } } public virtual string Text { get { return _Text; }

Get Control that triggered cross page postback

Hi I want to know if there is a way to get the control that triggered the postback,such as I have one page Page1.aspx with two buttons like<asp:Button id="btnCrossPost" runat="server" Text="Post To Another Page" PostBackUrl="Page2.aspx" CommandArgument="1"/><asp:Button id="btnCrossPost2" runat="server" Text="Post To Another Page 2" PostBackUrl="Page2.aspx" CommandArgument="2"/>and in Page2.aspx I want to get which button triggered the post back so that I can get the command argument which is vitalto the processing of the next page.Thanks.

How to determine if a user control is contained by the update panel that triggered async postback

Does anyone know a simple way to determine if a user control is contained in an update panel that was triggered for async postback?At the moment, the only pseudo logic for this I can think of is?'Loop through the update panel controls on the page and find the one that is involved in the postback (isInPartialRendering)'Try to find the user control as a child of the update panel

Find a form control that is created after postback

HiI have a drop down list (created during form design) with auto postback enabled. And I use AJAX to prevent 'visible postback'. When a user choose an item from the drop down list, the system will then perform a postback and created a set of form control's such as label, drop down list and text box for entry.Then, I will have a button (created during form design), and when I click on the button, i want to find for the form control that are created after the post back, but I cant find them!I wonder if those form controls are render to the web form?? But I have no problem finding the drop down list that is created during design time.Anyway I can find those form controls?Thank You.

Server Control - Implement Postback


Hi all,

I am writing a server control and need to implement postback. It is a simple calendar control - it renders a textbox and a button using the override of RenderContents which pops up a asp:Calendar control in a new window (written separately to the control) which sets the value of the textbox with javascript.

I just want the TextBox to keep it's value on postback. I inherit from WebControl rather than from TextBox as I thought it would be nice to have a greater level of control but if inheriting from TextBox is better practice I'd be interested instead for guidance on how to add to the render rather than overwrite it altogether (to add a button).

I'm not in the habit of writing such general questions but what I haven't been able to find is some decent resources to put me on the right path.

I've been looking at http://msdn.microsoft.com/en-us/library/aa720415(v=VS.71).aspx but can't get it working (I think I've implemented everything they say in the article, other than that I am using a different render method, but it doesn't change anything).

Does anyone have any simple examples or resources they could point me at to help?

Thanks in advance,


page inside update panel doesn't refresh the session object after postback of any control



I have many controls like dropdown, radiobuttonlist, etc on my page and I put all these controls inside the update panel so that the page doesn't look to be posting back when something is selected. Now the working on the page is very smooth. But the session object isn't getting refreshed even if I postback to the server and as a result even if the users are working on the page they are being sent to the login screen after 20 mins.

Is there anyway where I could put all the controls in update panel and still refresh the session after any postback(dropdown selection)

Any help is greatly appreciated.

Thanks in advance

People Picker control used in ASP.Net wizard control. Loses values on Postback?


I am using a people picker control in a custom visual web part with Visual Studio 2010, Sharepoint 2010.

The people picker control is on an asp.net wizard control.

On the wizard step with the people picker control, after postback the people picker control has selected values.

But when clicking the next or previous buttons of the wizard control, the people picker control does not retain its selected values.


Microsoft.SharePoint.WebControls.PeopleEditor pe

pe.AllowTypeIn = true;
pe.AutoPostBack = true;
pe.AllowEmpty = true;
pe.MultiSelect = false;
pe.SharePointGroup = "My SP Group Name";
pe.SelectionSet = "SPGroup";
pe.ValidatorEnabled = true;
pe.CommaSeparatedAccounts = pe.CommaSeparatedAccounts;

Any suggestions?


dynamic javascript of an .ascx control not updating on client upon async postback


I have a confusing state issue. I found a way around it, but I would like to know why this is happening. First of all, I am using .NET 3.5 and that can't change right now (an easy fix may be the fixed ID capabilities of .NET 4.0).

Type csType = this.GetType();
ClientScriptManager cs = Page.ClientScript;
string jScriptBlockName = "SignUpSignInNameAvailabilityScript";
if (!cs.IsClientScriptBlockRegistered(csType, jScriptBlockName))
{   //NOTE: verified code always enters this
    StringBuilder cstext2 = new StringBuilder();
    cstext2.Append("function GetSignUpSignInNameAvailabilityMessage() { var id = '"
          + CreateUserWizardStep1.ContentTemplateContainer.FindControl("iSignUpSignInNameAvailabilityMessage").ClientID
          + "'; alert(id); return id; }");
    cs.RegisterClientScriptBlock(csType, jScriptBlockName, cstext2.ToString(), true);

This code is in Page_Load of an ascx. The same control is drawn on two separate postbacks of an UpdatePanel in different places of the page thus giving them different client IDs. The code works correctly on the first refresh of web browser; but after UpdatePanel

lost child control after postback in panel control


Dear All!

I had a little project is create dynamic control. My project had get detail of content and replace in sign string , Add control in sign. After click button I will find in control, I had added on page load in panel. I can't get value in child control panel, Don't have control in panel . My source is

protected void Page_Load(object sender, EventArgs e)
         string config_design = GetConfigueKey(configDesign);
            Genform(config_design, GetContent(config_design));
        if (IsPostBack)
            btn_submit_click(sender, e);
            string config_design = GetConfigueKey(configDesign);
            Genform(config_design, GetContent(config_design));

What is difference in Page Life cycle in general postback and postback due to child control of updat



Since both general postback and postback due  to child control of update panel causes a postback and all events of page are loaded then what is the actual difference between  general postback and postback due to child controls of update panel.

Also, it is said that childern of update panel do a partial postback .Then how it is a partial postback ?? I am seeing that whole page life cycle is  happening even in partial postback ?

Can anyone explain this ?

Custom control's children do not persist contents after postback


I have created a really simple custom control to render panels into a page.  The code is below.  When I use my control and add any webcontrol to it, after each page postback the contents of these child controls vanishes.

I must have missed something really simple but please run the example to reproduce this.  Can anyone please enlighten me as to why the controls are being 'emptied' of their contents, and how I stop this occuring?

Crude diagram

Here is the code for the control

Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Text
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls

<ToolboxData("<{0}:MyTestControl runat=server></{0}:MyTestControl>"), ParseChildren(True)> _
Public Class MyTestControl
	Inherits CompositeControl
	Implements INamingContainer

	<NotifyParentProperty(True), PersistenceMode(PersistenceMode.InnerProperty)> _
	Public Property Panels() As List(Of Panel)
			Dim s As Object = ViewState("_StaticPanels")
			If s Is Nothing Then
				s = New List(Of Panel)
			End If
			Return CType(s, List(Of Panel))
		End Get
		Set(ByVal value As List(Of Panel))
			ViewState("_StaticPanels") = value
		End Set
	End Property

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend