Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET Ajax
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
 
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 18-Sep-12 8:54am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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:
 
ContentPlaceHolder pp = this.Master.FindControl("MainContent") as ContentPlaceHolder;
TextBox tb = pp.FindControl("TextBoxID") as TextBox;
  Permalink  
v2
Comments
aassaahh at 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?? .
MrProgrammer_78 at 22-Sep-12 19:06pm
   
No, this do not affect on performance, do it
aassaahh at 23-Sep-12 14:02pm
   
i have created master page for it but it is not working for me.showing null reference error
MrProgrammer_78 at 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 at 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.
MrProgrammer_78 at 24-Sep-12 20:14pm
   
which language you use? javascript??
you must write this code by c# or vb.net
aassaahh at 25-Sep-12 2:25am
   
ok can i get some sample code for this,but i dont want the whole page to be refresh.
MrProgrammer_78 at 25-Sep-12 2:31am
   
Please, tell me what do you want to do exactly, to give you the best scenario and whole code as your case exactly.
aassaahh at 25-Sep-12 4:46am
   
actually i have 50 dropdown on my page each populated with respect to other selected index change.i may have use update panel to prevent the page to be fully refreshed.but since you know update panel are not fast.that why i thought to write ajax code for it.but now i have to use code as
if (XmlHttpM.readyState == 4) {
// To make sure valid response is received from the server, 200 means response received is OK
<pre> if (XmlHttpM.status == 200) {
var strData = XmlHttpM.responseText;
//alert(strData)
if (strData != "") {


var arrscheme = strData.split("~");
id.length = 0;
 
for (i = 0; i < arrscheme.length - 1; i++) {
 
var strscheme = arrscheme[i];
//var arrschnm = strscheme.split("~");
 
// id.options[i] = new Option();
id.options[i] = new Option(strscheme, strscheme);
// id.options[i].value =parseInt(strscheme[0]) //arrschnm[0];
// id.options[i].text = (strscheme[0]) //arrschnm[1];
 
clearInterval(callfunc)
}
 
}
else {
 
id.length = 0;
id.options[0] = new Option();
id.options[0].value = "";
id.options[0].text = "";
}
// document.body.style.cursor = "auto";
} </pre>
for every dropdown ,i want to avoid this code ,and want to make a class and write a method there to bind dropdown or any control.
aassaahh at 25-Sep-12 4:49am
   
My mission is to bind dropdown and assign value to control depending on selectedindex change.and also want to keep in mind page should not be fully refreshed.and should be fast.
MrProgrammer_78 at 25-Sep-12 11:42am
   
Why you put textbox control on another page?
we use ajax to change value of controls on the same page as when you use ajax you do not redirect to the any page!!
if your textbox is on the same page you can do it.
aassaahh at 6-Oct-12 13:49pm
   
My textbox is in the page defualt1.aspx ,i want to assign value to this textbox from default2.aspx.
I am redirecting to defualt2.aspx by ajax code.ie
var requestUrl = "Default2.aspx?id="+txtnameid+"";

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

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

  Print Answers RSS
0 OriginalGriff 410
1 Jochen Arndt 200
2 Richard MacCutchan 135
3 DamithSL 105
4 PIEBALDconsult 90
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,032
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,220


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 18 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100