Click here to Skip to main content
15,881,898 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,can i find id of any control of aspx page in some different
aspx page.
let say i have one textbox in parent page (default1.aspx) and i want to find this id in diffenrent page let say default2.aspx and assign value to the textbox in the page
default1.
i am going to dafault2.aspx by ajax code as

C#
var txtnameid = document.getElementById(id);

          CreateXmlHttp();

          var requestUrl = "Default2.aspx?id="+txtnameid+"";

          if (XmlHttp) {
              XmlHttp.onreadystatechange = function() { setvalue(txtnameid) };
              XmlHttp.open("GET", requestUrl, true);
              XmlHttp.send(null);
          }


function setvalue(id)
    { 
 	    // To make sure receiving response data from server is completed
	    if(XmlHttp.readyState == 4)
	    {	
		    // To make sure valid response is received from the server, 200 means response received is OK
		    if(XmlHttp.status == 200)
		    {		    
		         var strData = XmlHttp.responseText;
                id.value=strData

		    }
		    else {
	
		    }
    		
	    }

    }    


The above code is working for me, but i want to find id in default2.aspx and assign value to textbox which is present in default1.aspx from default2.aspx .
How can i do this.please help
Posted

1 solution

yes you can do this but you must use master page through which you can find and reach to any control you want,
create master page for the two pages and this code to find control:

C#
ContentPlaceHolder pp = this.Master.FindControl("MainContent") as ContentPlaceHolder;
TextBox tb = pp.FindControl("TextBoxID") as TextBox;
 
Share this answer
 
v2
Comments
aassaahh 19-Sep-12 10:14am    
yes ,you are right i can use this techniq but this will reduce my performance as i think since there will be two page event for master and normal aspx page ,am i right?? .
MrLonely_2 22-Sep-12 19:06pm    
No, this do not affect on performance, do it
aassaahh 23-Sep-12 14:02pm    
i have created master page for it but it is not working for me.showing null reference error
MrLonely_2 24-Sep-12 1:07am    
Is the second page (default2) which you want to get control is previous page for default1 ??
if yes you can use PreviousPage Property like that:

TextBox txt = (TextBox)Page.PreviousPage.FindControl("serverNameText");
aassaahh 24-Sep-12 6:34am    
i am going to that page using this code CreateXmlHttp();

var requestUrl = "Default2.aspx?id="+txtnameid+"";

if (XmlHttp) {
XmlHttp.onreadystatechange = function() { setvalue(txtnameid) };
XmlHttp.open("GET", requestUrl, true);
XmlHttp.send(null);
}
I am still not getting ID.

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