Click here to Skip to main content
16,023,224 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I just want to access the html input text control of master page in my another page containing master page.I have a input text control name txtsearch and I access it in default2.aspx.cs file. I have written the code on Page_Load event as

C#
HtmlInputText src = (HtmlInputText) Master.FindControl("txtsearch");
src.value=source;


where, source is the variable which is assigned value from
C#
Request.Querystring["s"];


The problem is that in code src.value = source, there is an error:
Object reference not set to an instance of an object.

I don't know why it is coming? Please help me as soon as possible.
Posted
Updated 17-Jun-10 2:10am
v2

nishi2010 wrote:
The problem is that in code src.value = source, there is an error:
Object reference not set to an instance of an object


This simply means there is an issue at line:
nishi2010 wrote:
HtmlInputText src = (HtmlInputText) Master.FindControl("txtsearch");


Use a DEBUGGER and see if you are getting anything for '(HtmlInputText) Master.FindControl("txtsearch")'?

It doesn't look like. src is null after the execution of this line and thus, src.Value is nothing.

Now few more things:
1. Make sure you have runat=server on that htmlInput control(which looks like used as type="text")
2. src.Value = "someValue";
Your code snippet states it's small 'v' in value. Might be a typo here, still just check it.
 
Share this answer
 
Comments
nishi2010 18-Jun-10 5:46am    
i had debugg the code HtmlInputText src = (HtmlInputText) Master.FindControl("txtsearch"); but it assign null in it.
I can not use runat=server in input text control of master page becoz i m calling a javascript func on its onkeyup event to autocomplete the text box which is not calling when i use runat=server.so if u have some alternate plzz give me i need it as soon as possible.

Thnaks for u r reply
nishi2010 wrote:

I can not use runat=server in input text control of master page becoz i m calling a javascript func on its onkeyup event


If you are not providing runat="server" then how come you can expect the textbox to be visible on server side? Thats the reason you get null.

Now, do the following:
1. Provide runat="server" to the input control
2. Now tie OnKeyUp event to input tex control
3. Do a view-source and see what is the name rendered while page loads. Use this ID in your autocomplete function. Point is, if you use runat="server" then Master page id will get appended to the input control ID. Currently you must be directly using 'txtsearch' in your javascript function which will no more work once it's a server control. You need to give full ID.

Try that.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900