Click here to Skip to main content
15,893,487 members
Home / Discussions / C#
   

C#

 
GeneralRe: C# TCPClient Connect not working when VPN is present. Pin
Ashley Glenister17-Mar-22 6:16
Ashley Glenister17-Mar-22 6:16 
QuestionProblems when reading a Excel file with numbers. Pin
jwradhe17-Mar-22 0:31
jwradhe17-Mar-22 0:31 
AnswerRe: Problems when reading a Excel file with numbers. Pin
Estys17-Mar-22 1:32
Estys17-Mar-22 1:32 
GeneralRe: Problems when reading a Excel file with numbers. Pin
jwradhe17-Mar-22 2:34
jwradhe17-Mar-22 2:34 
QuestionI want the MySQL 5.7.21 server to be installed from my application Pin
Member 1227854216-Mar-22 7:59
Member 1227854216-Mar-22 7:59 
AnswerRe: I want the MySQL 5.7.21 server to be installed from my application Pin
OriginalGriff16-Mar-22 9:27
mveOriginalGriff16-Mar-22 9:27 
GeneralRe: I want the MySQL 5.7.21 server to be installed from my application Pin
Member 1227854218-Mar-22 4:45
Member 1227854218-Mar-22 4:45 
GeneralRe: I want the MySQL 5.7.21 server to be installed from my application Pin
RobertSF18-Mar-22 7:24
professionalRobertSF18-Mar-22 7:24 
QuestionHow to read a Card Reader in C# ? Pin
Filip D. Williams14-Mar-22 23:57
Filip D. Williams14-Mar-22 23:57 
AnswerRe: How to read a Card Reader in C# ? Pin
Richard MacCutchan15-Mar-22 1:11
mveRichard MacCutchan15-Mar-22 1:11 
QuestionWhat are Good Things to Know in a C# Interview? Pin
Xarzu14-Mar-22 11:52
Xarzu14-Mar-22 11:52 
AnswerRe: What are Good Things to Know in a C# Interview? Pin
OriginalGriff14-Mar-22 12:29
mveOriginalGriff14-Mar-22 12:29 
AnswerRe: What are Good Things to Know in a C# Interview? Pin
Dave Kreskowiak14-Mar-22 14:36
mveDave Kreskowiak14-Mar-22 14:36 
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 

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.