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

ASP.NET

 
QuestionAutomatically add a numeric value to the SQL Server Database after the expiration of a certain date( Date will vary ) Pin
hilbiazhar9-Jun-14 5:57
hilbiazhar9-Jun-14 5:57 
AnswerRe: Automatically add a numeric value to the SQL Server Database after the expiration of a certain date( Date will vary ) Pin
Richard Deeming9-Jun-14 6:10
mveRichard Deeming9-Jun-14 6:10 
Question[ASP.NET C#] Postback and updatepanel issues. Pin
Member 79124618-Jun-14 11:11
Member 79124618-Jun-14 11:11 
SuggestionRe: [ASP.NET C#] Postback and updatepanel issues. Pin
Dusara Maulik9-Jun-14 2:24
Dusara Maulik9-Jun-14 2:24 
GeneralRe: [ASP.NET C#] Postback and updatepanel issues. Pin
Member 79124619-Jun-14 2:53
Member 79124619-Jun-14 2:53 
GeneralRe: [ASP.NET C#] Postback and updatepanel issues. Pin
jkirkerx11-Jun-14 13:24
professionaljkirkerx11-Jun-14 13:24 
GeneralRe: [ASP.NET C#] Postback and updatepanel issues. Pin
Member 791246114-Jun-14 4:21
Member 791246114-Jun-14 4:21 
GeneralRe: [ASP.NET C#] Postback and updatepanel issues. Pin
jkirkerx14-Jun-14 8:33
professionaljkirkerx14-Jun-14 8:33 
I write in VB, but I wrote this as a quick example and tested it. The controls persist throughout the page life cycle.
Perhaps this example will give you an idea of how to write controls in code behind so that they persist.

I'm curious if others read this post, I use the With statement to include stuff like control properties.
I was not able to figure out how to use Style in the curly brackets like in the update panel, and was forced to use the control variable name instead. Lots of extra typing. If anyone knows how to add style using the curly brackets let me know.

<%@ Page 
    Title="Test" 
    Language="C#" 
    AutoEventWireup="true" 
    CodeFile="Default2.aspx.cs" 
    Inherits="Default2" %>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
</head>
    <body id="bodytag" runat="server" class="PageBackground">        
        <form id="frmDefault" runat="server">
            <asp:ScriptManager ID="ScriptManager1" runat="server" />
            <div id="wf_container" runat="server">


            </div>
        </form>
    </body>
</html>


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default2 : System.Web.UI.Page
{

    private TextBox txt_lc_userName;

    protected void Page_Init(object sender, EventArgs e)
    {

        var up_login_container = new UpdatePanel() {
            ID = "_up_login_container",
            ClientIDMode = ClientIDMode.Static,
            UpdateMode = UpdatePanelUpdateMode.Conditional,
            ChildrenAsTriggers = false
        };
        wf_container.Controls.Add(up_login_container);

        var div_login_container = new Panel();
        div_login_container.ID = "_div_login_container";
        div_login_container.ClientIDMode = ClientIDMode.Static;
        div_login_container.Style.Add(HtmlTextWriterStyle.Width, "100%");
        div_login_container.Style.Add(HtmlTextWriterStyle.Height, "400px");       
        up_login_container.ContentTemplateContainer .Controls.Add(div_login_container);

        var div_lc_username = new Panel();
        div_lc_username.Style.Add(HtmlTextWriterStyle.Width, "50%");
        div_lc_username.Style.Add(HtmlTextWriterStyle.Height, "26px");
        div_lc_username.Style.Add(HtmlTextWriterStyle.TextAlign, "left");
        div_login_container.Controls.Add(div_lc_username);

        txt_lc_userName = new TextBox();
        txt_lc_userName.ID = "_txt_lc_userName";
        txt_lc_userName.ClientIDMode = ClientIDMode.Static;
        txt_lc_userName.Style.Add(HtmlTextWriterStyle.Width, "90%");
        txt_lc_userName .Style.Add(HtmlTextWriterStyle.Height, "20px");
        div_lc_username.Controls.Add(txt_lc_userName);

        var div_lc_submit = new Panel();
        div_lc_submit.Style.Add(HtmlTextWriterStyle.Width, "50%");
        div_lc_submit.Style.Add(HtmlTextWriterStyle.Height, "46px");
        div_lc_submit.Style.Add(HtmlTextWriterStyle.TextAlign, "left");
        div_login_container.Controls.Add(div_lc_submit);

        var bt_lc_submit = new Button();
        bt_lc_submit.ID = "_bt_lc_submit";
        bt_lc_submit.Text = "Submit";
        bt_lc_submit.Click += new System.EventHandler(bt_lc_submit_click);
        div_lc_submit.Controls.Add(bt_lc_submit);

        var bt_lc_submit_trigger = new AsyncPostBackTrigger();
        bt_lc_submit_trigger.ControlID = "_bt_lc_submit";
        bt_lc_submit_trigger.EventName = "click";
        up_login_container.Triggers.Add(bt_lc_submit_trigger );


    }


    protected void Page_Load(object sender, EventArgs e)
    {

        if (!Page.IsPostBack)
        {


        }
        else
        {



        }

    }
    protected void bt_lc_submit_click(object sender, EventArgs e)
    {
        string m_userName = txt_lc_userName.Text.Trim();
        Response.Write(m_userName);


    }
}

QuestionSession for Listbox Pin
Dalina Cheriyan6-Jun-14 3:11
Dalina Cheriyan6-Jun-14 3:11 
AnswerRe: Session for Listbox Pin
ZurdoDev6-Jun-14 10:29
professionalZurdoDev6-Jun-14 10:29 
GeneralHow to increase .net application performance Pin
venumadhav.narla7776-Jun-14 0:39
venumadhav.narla7776-Jun-14 0:39 
GeneralRe: How to increase .net application performance Pin
Richard Deeming6-Jun-14 1:01
mveRichard Deeming6-Jun-14 1:01 
AnswerRe: How to increase .net application performance Pin
thatraja6-Jun-14 9:58
professionalthatraja6-Jun-14 9:58 
Question'Submit' button related errors Pin
Member 87616675-Jun-14 14:26
Member 87616675-Jun-14 14:26 
AnswerRe: 'Submit' button related errors Pin
Richard Deeming6-Jun-14 0:59
mveRichard Deeming6-Jun-14 0:59 
GeneralRe: 'Submit' button related errors Pin
Member 87616676-Jun-14 6:02
Member 87616676-Jun-14 6:02 
GeneralRe: 'Submit' button related errors Pin
Richard Deeming6-Jun-14 7:33
mveRichard Deeming6-Jun-14 7:33 
GeneralRe: 'Submit' button related errors Pin
Member 87616676-Jun-14 7:43
Member 87616676-Jun-14 7:43 
QuestionBeginner: using update_demo.asp - Datatype Mismatch Error Pin
Istteffanny Isloure Araujo4-Jun-14 22:49
Istteffanny Isloure Araujo4-Jun-14 22:49 
AnswerRe: Beginner: using update_demo.asp - Datatype Mismatch Error Pin
thatraja4-Jun-14 23:52
professionalthatraja4-Jun-14 23:52 
QuestionUnable to close a modal pop up after opening an pdf document Pin
aditya kiran maroju4-Jun-14 18:36
aditya kiran maroju4-Jun-14 18:36 
QuestionRe: Unable to close a modal pop up after opening an pdf document Pin
Vasudevan Deepak Kumar13-Jun-14 2:35
Vasudevan Deepak Kumar13-Jun-14 2:35 
Questionhighlight main menu item of current page. Also highlight when sub menu item is selected through javascript in ASP.net Pin
hilbiazhar4-Jun-14 2:41
hilbiazhar4-Jun-14 2:41 
Questionkinect with web Pin
vinayak.ghanti3-Jun-14 20:42
professionalvinayak.ghanti3-Jun-14 20:42 
AnswerRe: kinect with web Pin
Richard MacCutchan3-Jun-14 22:04
mveRichard MacCutchan3-Jun-14 22:04 

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.