Link to home
Start Free TrialLog in
Avatar of tia_kamakshi
tia_kamakshiFlag 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

Avatar of Daniel Van Der Werken
Daniel Van Der Werken
Flag of United States of America image

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
Avatar of Jorge_Laines_PE
Jorge_Laines_PE
Flag of Peru image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of 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
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

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
Run the page, do a View Source, and put that output here for us to look at.
Post your xml and xslt please, to give you another approach
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
hi

are you looking into this? this is urgent to me

please guide

thanks
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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/questions/27240176/runat-server-is-not-working-when-transforming-xml-and-xslt.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