Finding HtmlInputText  in asp.net c# 2.0

tia_kamakshi
tia_kamakshi used Ask the Experts™
on
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

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Daniel Van Der WerkenIndependent Consultant

Commented:
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?
Senior Software Engineer
Commented:
1. Dynamic HTML controls do not have runat="server"
2. Your dinamic HTML control should have "name" and also "id" parameters declared, this should be the code:

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

Open in new window


3. Why are you using  xml , xslt for creating dynamic HTML controls, you can create them within code.

Author

Commented:
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

Author

Commented:
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

Author

Commented:
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 WerkenIndependent Consultant

Commented:
Run the page, do a View Source, and put that output here for us to look at.
Jorge_Laines_PESenior Software Engineer

Commented:
Post your xml and xslt please, to give you another approach

Author

Commented:
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

Author

Commented:
hi

are you looking into this? this is urgent to me

please guide

thanks
Daniel Van Der WerkenIndependent Consultant
Commented:
I don't see a <form> tag in your HTML.  I think you need to have an <input> tag within a <form> tag for it to be valid and working properly.

Wrap all this in a <form>.

http://www.w3schools.com/tags/tag_input.asp

Author

Commented:
Thanks Dan7el

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

The problem looks to me is related to
http://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

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial