Click here to Skip to main content
15,886,519 members
Home / Discussions / C#
   

C#

 
GeneralRe: What are Good Things to Know in a C# Interview? Pin
lmoelleb14-Mar-22 23:28
lmoelleb14-Mar-22 23:28 
GeneralRe: What are Good Things to Know in a C# Interview? Pin
Member 1227854218-Mar-22 8:25
Member 1227854218-Mar-22 8:25 
AnswerRe: What are Good Things to Know in a C# Interview? Pin
Eddy Vluggen14-Mar-22 14:39
professionalEddy Vluggen14-Mar-22 14:39 
Questionc sharp Pin
vishnu satpathy12-Mar-22 7:26
vishnu satpathy12-Mar-22 7:26 
AnswerRe: c sharp Pin
OriginalGriff12-Mar-22 7:37
mveOriginalGriff12-Mar-22 7:37 
QuestionSend a mail that has Arabic characters using Gmail API Pin
mahmoud199011-Mar-22 11:05
mahmoud199011-Mar-22 11:05 
AnswerRe: Send a mail that has Arabic characters using Gmail API Pin
Randor 11-Mar-22 13:17
professional Randor 11-Mar-22 13:17 
QuestionGenerate Textbox on runtime Pin
Saim Ullah 20219-Mar-22 22:47
Saim Ullah 20219-Mar-22 22:47 
Hi Folks,
i have created a simple page which adds textbox dynamically. 1st textbox creates successfully but afterwards it showes error of object reference not set to an instance of an object.

it is not getting the ID of the panel which i contains the textbox.

my aspx file is....

<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/Header.Master" CodeFile="testpage.aspx.cs"
Inherits="testpage" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<asp:content id="HeaderContent" runat="server" contentplaceholderid="head">

<asp:content id="BodyContent" runat="server" contentplaceholderid="ContentPlaceHolder1">
<asp:panel id="pnlTextBoxes" runat="server">



<asp:button id="btnAdd" runat="server" text="Add New" onclick="AddTextBox">
<asp:button id="btnGet" runat="server" text="Get Values" onclick="GetTextBoxValues">



and .cs file is....

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

public partial class testpage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
     protected void Page_PreInit(object sender, EventArgs e)
    {
        List<string> keys = Request.Form.AllKeys.Where(key => key.Contains("txtDynamic")).ToList();
        int i = 1;
        foreach (string key in keys)
        {
            this.CreateTextBox("txtDynamic" + i);
            i++;
        }
    }

    protected void AddTextBox(object sender, EventArgs e)
    {
        int index = pnlTextBoxes.Controls.OfType<TextBox>().ToList().Count + 1;
        this.CreateTextBox("txtDynamic" + index);
    }

    private void CreateTextBox(string id)
    {
        TextBox txt = new TextBox();
        txt.ID = id;
        pnlTextBoxes.Controls.Add(txt);

        Literal lt = new Literal();
        lt.Text = "<br />";
        pnlTextBoxes.Controls.Add(lt);
    }

    protected void GetTextBoxValues(object sender, EventArgs e)
    {
        string message = "";
        foreach (TextBox textBox in pnlTextBoxes.Controls.OfType<TextBox>())
        {
            message += textBox.ID + ": " + textBox.Text + "\\n";
        }
        ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "alert('" + message + "');", true);
    }
}

QuestionRe: Generate Textbox on runtime Pin
Richard MacCutchan9-Mar-22 23:38
mveRichard MacCutchan9-Mar-22 23:38 
AnswerRe: Generate Textbox on runtime Pin
Saim Ullah 202110-Mar-22 0:23
Saim Ullah 202110-Mar-22 0:23 
GeneralRe: Generate Textbox on runtime Pin
Richard MacCutchan10-Mar-22 0:31
mveRichard MacCutchan10-Mar-22 0:31 
GeneralRe: Generate Textbox on runtime Pin
Saim Ullah 202110-Mar-22 0:41
Saim Ullah 202110-Mar-22 0:41 
GeneralRe: Generate Textbox on runtime Pin
Richard MacCutchan10-Mar-22 0:45
mveRichard MacCutchan10-Mar-22 0:45 
AnswerRe: Generate Textbox on runtime Pin
OriginalGriff10-Mar-22 0:12
mveOriginalGriff10-Mar-22 0:12 
GeneralRe: Generate Textbox on runtime Pin
Saim Ullah 202110-Mar-22 0:34
Saim Ullah 202110-Mar-22 0:34 
GeneralRe: Generate Textbox on runtime Pin
OriginalGriff10-Mar-22 1:08
mveOriginalGriff10-Mar-22 1:08 
GeneralRe: Generate Textbox on runtime Pin
Saim Ullah 202110-Mar-22 7:59
Saim Ullah 202110-Mar-22 7:59 
AnswerRe: Generate Textbox on runtime Pin
RedDk10-Mar-22 8:26
RedDk10-Mar-22 8:26 
GeneralRe: Generate Textbox on runtime Pin
Richard MacCutchan10-Mar-22 22:21
mveRichard MacCutchan10-Mar-22 22:21 
GeneralRe: Generate Textbox on runtime Pin
RedDk11-Mar-22 8:06
RedDk11-Mar-22 8:06 
QuestionC# File.Create terminating WimForm app wiith no error thrown ? Pin
BillWoodruff8-Mar-22 5:03
professionalBillWoodruff8-Mar-22 5:03 
AnswerRe: C# File.Create terminating WimForm app wiith no error thrown ? Pin
Pete O'Hanlon8-Mar-22 5:24
mvePete O'Hanlon8-Mar-22 5:24 
GeneralRe: C# File.Create terminating WimForm app wiith no error thrown ? Pin
BillWoodruff8-Mar-22 6:27
professionalBillWoodruff8-Mar-22 6:27 
GeneralRe: C# File.Create terminating WimForm app wiith no error thrown ? Pin
Pete O'Hanlon8-Mar-22 20:42
mvePete O'Hanlon8-Mar-22 20:42 
GeneralRe: C# File.Create terminating WimForm app wiith no error thrown ? Pin
BillWoodruff8-Mar-22 21:19
professionalBillWoodruff8-Mar-22 21:19 

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.