Click here to Skip to main content
15,902,893 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: Override page constructor Pin
User 9148332-Oct-06 22:01
User 9148332-Oct-06 22:01 
GeneralRe: Override page constructor Pin
minhpc_bk2-Oct-06 22:17
minhpc_bk2-Oct-06 22:17 
GeneralRe: Override page constructor Pin
User 9148333-Oct-06 4:20
User 9148333-Oct-06 4:20 
GeneralRe: Override page constructor Pin
minhpc_bk3-Oct-06 10:56
minhpc_bk3-Oct-06 10:56 
GeneralRe: Override page constructor Pin
User 9148335-Oct-06 1:37
User 9148335-Oct-06 1:37 
GeneralRe: Override page constructor Pin
minhpc_bk5-Oct-06 14:54
minhpc_bk5-Oct-06 14:54 
GeneralRe: Override page constructor Pin
User 9148336-Oct-06 1:50
User 9148336-Oct-06 1:50 
GeneralRe: Override page constructor Pin
minhpc_bk9-Oct-06 18:12
minhpc_bk9-Oct-06 18:12 
Normally, there are a couple of reasons that causes the ViewState of a control to get lost:

+ The control has the ViewState disabled.
+ The control is dynamically readded after the ViewState is loaded.
+ The control has different ID when the ViewState is loaded. For example, when the ViewState is saved the control'ID is "Radio1", but when the ViewState is loaded on postback the value of the ID is "Radio2".

Below is a working example:

//web page .aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default1.aspx.cs" Inherits="Default1" %>
        
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
          
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:PlaceHolder runat="server" ID="PlaceHolderControl1"></asp:PlaceHolder>
        <br />
        <asp:Button runat="server" ID="btnPushMe" Text="Pushed Me!" OnClick="btnPushMe_Click" />    
    </div>
    </form>
</body>
</html>
       
//Code-behind
public partial class Default1 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Table table = new Table();
        for (int rowIndex = 0; rowIndex < 3; rowIndex++)
        {
            TableRow row = new TableRow();
            TableCell cell = new TableCell();
            RadioButton radio = new RadioButton();
            radio.ID = "Radio_" + rowIndex.ToString();
            radio.GroupName = "RadioGroup";
                    
            cell.Controls.Add(radio);
            row.Cells.Add(cell);
            table.Rows.Add(row);
        }
               
        PlaceHolderControl1.Controls.Add(table);
    }
             
    protected void btnPushMe_Click(object sender, EventArgs e)
    {
        for (int rowIndex = 0; rowIndex < 3; rowIndex++)
        {
            RadioButton radio = (RadioButton)PlaceHolderControl1.FindControl("Radio_" + rowIndex.ToString());
            Response.Write(string.Format("Radio {0}'s checked state : {1} <br>", rowIndex, radio.Checked));
        }
    }
}

Questiondatagrid NumericPages mix up Pin
keroed_edmond2-Oct-06 10:00
keroed_edmond2-Oct-06 10:00 
AnswerRe: datagrid NumericPages mix up Pin
minhpc_bk2-Oct-06 15:44
minhpc_bk2-Oct-06 15:44 
QuestionRetain CSS format reading a Page Pin
VickyC#2-Oct-06 9:20
VickyC#2-Oct-06 9:20 
AnswerRe: Retain CSS format reading a Page Pin
Guffa2-Oct-06 10:11
Guffa2-Oct-06 10:11 
GeneralRe: Retain CSS format reading a Page Pin
VickyC#2-Oct-06 10:55
VickyC#2-Oct-06 10:55 
AnswerRe: Retain CSS format reading a Page Pin
Guffa2-Oct-06 21:43
Guffa2-Oct-06 21:43 
QuestionConfirm User Registration Pin
TheEagle2-Oct-06 9:10
TheEagle2-Oct-06 9:10 
AnswerRe: Confirm User Registration Pin
morteza572-Oct-06 12:05
morteza572-Oct-06 12:05 
GeneralRe: Confirm User Registration Pin
TheEagle3-Oct-06 9:51
TheEagle3-Oct-06 9:51 
QuestionAsp help Pin
Larsson2-Oct-06 6:31
Larsson2-Oct-06 6:31 
AnswerRe: Asp help Pin
minhpc_bk2-Oct-06 15:53
minhpc_bk2-Oct-06 15:53 
QuestionLooking for XML Web services Pin
Sudhakar Pasupunuri2-Oct-06 6:03
Sudhakar Pasupunuri2-Oct-06 6:03 
AnswerRe: Looking for XML Web services Pin
minhpc_bk2-Oct-06 16:02
minhpc_bk2-Oct-06 16:02 
AnswerRe: Looking for XML Web services Pin
Exelioindia2-Oct-06 22:56
Exelioindia2-Oct-06 22:56 
QuestionA basic Problem with buttons Pin
Britney S. Morales2-Oct-06 4:59
Britney S. Morales2-Oct-06 4:59 
AnswerRe: A basic Problem with buttons Pin
sanju02762-Oct-06 7:29
sanju02762-Oct-06 7:29 
AnswerRe: A basic Problem with buttons Pin
minhpc_bk2-Oct-06 16:05
minhpc_bk2-Oct-06 16:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.