Avatar of tia_kamakshi
tia_kamakshi
Flag for United Arab Emirates asked on

Finding HtmlInputText in asp.net c# 2.0

Hi,

I am working on asp.net 2.0 using c#

I am creating form on the aspx page by transforming xml with xslt and therefore creating html conrols in the form

I have created html text field from xml , xslt as follows

<input type="text" name="txtCompanyName" runat="server" class="formText" />

Now at code behind I am writting a code on page load method (just to test if code is finding html control or not)

HtmlInputText hCompany = (HtmlInputText)Page.FindControl("txtCompanyName");
string txtCompanyName = hCompanyName.Value;

I am getting null pointer exception because hCompany is null

I have also tried

HtmlInputText hCompany = (HtmlInputText)this.FindControl("txtCompanyName");

but it is not working

I am rendering xml with xslt on aspx page by below code:

<asp:Xml runat="server" ID="tblTenderDetail" Document="myxml.xml"  TransformSource="tenderDetail.xsl" >

I also tried

HtmlInputText hCompany = (HtmlInputText)tblTenderDetail.Page.FindControl("txtCompanyName");


Please guide

C#

Avatar of undefined
Last Comment
tia_kamakshi

8/22/2022 - Mon
Daniel Van Der Werken

What happens if you do this?

object oCompany = Page.FindControl( "txtCompanyName" );

What is oCompany?  Null?

Also, is this inside any other control like a repeater or such?
ASKER CERTIFIED SOLUTION
Jorge_Laines_PE

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
tia_kamakshi

ASKER
yes oCompany is also null

It is under contentPlaceHolder as aspx page has masterpage in it

so the code is

<asp:Content ID="Content6" ContentPlaceHolderID="MainContent" runat="Server">
<asp:Xml runat="server" ID="tblTenderDetail" Document="myxml.xml"  TransformSource="tenderDetail.xsl" >
</asp:Xml>

</asp:Content
tia_kamakshi

ASKER
As suggested I have added name and id both as follows:

<input type="text" id="txtCompanyName" name="txtCompanyName" class="formText" />

and tried

HtmlInputText hCompany = (HtmlInputText)Page.Master.FindControl("txtCompanyName");

This also not helped me

Please suggest

This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
tia_kamakshi

ASKER
I have the inputs in xml only. This xml is published by external agency, therefore xml and xslt is used

Do you have any suggestion other than this

Please suggest that as well
Daniel Van Der Werken

Run the page, do a View Source, and put that output here for us to look at.
Jorge_Laines_PE

Post your xml and xslt please, to give you another approach
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
tia_kamakshi

ASKER
Hi,

Please find my code attached.

I have renamed all files with .txt extension at the last. so that experts exchange should allow me to upload the file

Please suggest
code.zip
tia_kamakshi

ASKER
hi

are you looking into this? this is urgent to me

please guide

thanks
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
tia_kamakshi

ASKER
Thanks Dan7el

I have now added form tag having runat server in it.

The problem looks to me is related to
https://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_27240176.html

my html control is not running at server, therefore it is displaying runat server with input tag. means .net is not rendering this control on the server and taking output as string after transformation of xml and xslt

Please suggest
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes