|
The javascript function is ok i guess!
An alert box will be shown if the condition is met and return false;
else return true thereby the code in the event should be executed - this part is not happenning.
Gautham
|
|
|
|
|
Can you post the html part along with javascript function and Dropdonelist_selectedIndexChanged event code
Thanks and Regards
Sandeep
If If you look at what you do not have in life, you don't have anything,
If you look at what you have in life, you have everything... "
|
|
|
|
|
function function1()
{
alert("Hi");
return true;
}
In pageLoad
ddl1.Attributes.Add("onChange", "javascript:return function1();");
The alert box is being displayed but after that the code in the selection changed event is not being executed.
If there are no return statments then both the events are being executed.
So, is it a problem with catching the return true/false??
Gautham
|
|
|
|
|
hi...
ihave 10 textboxes and some other controls on my aspx page...now i want the count of the textboxes only on the aspx page...how to do it...
any one help me regarding this...
Pradeep Reddy
|
|
|
|
|
Hi,
You can try the following code.
int textcount = 0;
foreach ( Control ctrl in Page.Controls )
{
if ( ctrl is TextBox )
{
textcount ++;
}
}
I hope this will help you.
Thanks and Regards,
Chetan Ranpariya
|
|
|
|
|
thanks for the reply...
but it is not working...
Pradeep Reddy
|
|
|
|
|
Hi
What do u mean by "Its not working"?
Do u get any error?
Thanks and Regards,
Chetan Ranpariya
|
|
|
|
|
foreach(Control c1 in this.Controls)
{
if(c1.GetType()==typeof(TextBox))
{
increment your count....
}
}
Gautham
|
|
|
|
|
thanks for the reply...
but it is not working...
Pradeep Reddy
|
|
|
|
|
private void Button1_Click(object sender, System.EventArgs e)
{
int grandTotal = 0;
for (int i = 1; i <= Count; i++)
{
grandTotal += int.Parse(Request.Form[
String.Format("txtBox{0}", i)]);
}
for (int i = 1; i <= Count-1; i++)
{
TextBox txt = (TextBox) Panel1.FindControl(
String.Format("txtBox{0}", i));
grandTotal += int.Parse(txt.Text.ToString());
}
Response.Write(grandTotal);
}
Hope this code will help you.
Regards,
Satips.
|
|
|
|
|
thanks for the replybut what is the Count here? and what about pannel...?
Pradeep Reddy
|
|
|
|
|
Count refers to the number of textboxes.
Panel is where i put the textboxes,i.e., the textbox are all inside the Panel.
Regards,
Satips.
|
|
|
|
|
how will we initilize the Count...
Pradeep Reddy
|
|
|
|
|
i have a textbox in webusercontrol, i used webusercontrol in my aspx page....
now the problem is, how to get the value of the textbox in to my aspx page code behind...
any one plz help me regarding this...
Pradeep Reddy
|
|
|
|
|
HI,
Create a public property in your webusercontrol which gives u the value of the textbox.
public string TextValue
{
get{ return textbox.text; }
}
now you can use this property in your aspx page like this.
Strint str = WebUserControl1.TextValue;
I hope this will help u.
Thanks and Regards,
Chetan Ranpariya
|
|
|
|
|
thanks for the reply...
but this is not the solution for my problem...
actually i have to get the textbox value into my aspx page codebehind...
Pradeep Reddy
|
|
|
|
|
Hi,
The way I told you is for getting the textbox value of your usercontrol in the aspx codebehind.
Have u tried the way I suggested?
If yes then what is the error r u getting?
Thanks and Regards,
Chetan Ranpariya
|
|
|
|
|
well the above solution is fine but if u have five nested controls then for one control u'll have write a lot of code, properties or whtever...
there is an other solution,
u could use the folling code....
ctype(UserControlid.findControl("RequiredControlID"),textbox).text
thts it.
hope it works for u.
Allah Hafiz
|
|
|
|
|
Hi,
I m confused by the term "five nested controls".
Can you please elaborate the thing?
Thanks and Regards,
Chetan Ranpariya
|
|
|
|
|
well nested controls means if u have a user control, within tht there is an other, n with the innerone there is another one and so on and in the fifth control u have an asp.net control. it would be difficult to make properties instead of tht method ,tht i've mentioned is quiete simple to me. i don't how do u find it. but i find it quite simple.
regards.
|
|
|
|
|
Hi,
Did this work at your side?
I have tried this but its giving me NullReferenceException.
I have a usercontrol "GetCategory.ascx" in that there is one gridview with id "gvSearchResult".
I put "GetCategory.ascx" in to "Parent1.ascx" then I put "Parent1.ascx" in to "Parent2.ascx".
I used "Parent2.ascx" in to my Text.aspx page.
and write the following code in the Page_Load event of "Text.aspx".
GridView gv = ( GridView )Parent2_1.FindControl( "gvSearchResult" );
Response.Write( gv.ID ); // On this line it gives me NullReferenceException. Means it could not find controls with "gvSearchResult" in Parent2_1 control on the page.
Can you tell me why is it like that or am I making any mistake?
Thanks and Regards,
Chetan Ranpariya
|
|
|
|
|
hi,
well....
yes definitely u r committing mistakes.
first tell me tht when u execute
GridView gv = ( GridView )Parent2_1.FindControl( "gvSearchResult" );
above line, have u bound the gridview.
now, if u've bounded it, still u r commiting a mistake in the following line;
GridView gv = ( GridView )Parent2_1.FindControl( "gvSearchResult" )
the correctone is:
GridView gv=(GridView) Parent2_1.findcontrol("parent1").findcontrol("getcategory").findcontrol("gvSearchResult");
keep two things in mind.
u don't have to write the names infact there ID must be written given to findcontrol method.
and second thing is make sure ur datagrid is filled before u findit.
these are the two reasons which u need to correct...
hope it works.
regards.
|
|
|
|
|
Hi,
I am executing that line after binding the gridview in the usercontrol
and by the way there is no need to bind the gridview before you access it in your code because to bind gridview to any datasource you need to have an access to instance of gridview.
Try it!!!!!!!!!!!!!!!!
Your solution to find controls in the usercontrol is good but for that one should know about the IDs of all the controls and their types in the all the usercontrols.
What about making related properties whereever need in all the controls so that they can be used with without worrying about types and IDs of nested controls and the undelaying complaxity because properties are there for hide complexity only and improve the accessibility and readbility.
Think on it!!!!!!!!!!!!!!!!!!!!!!!
Thanks and Regards,
Chetan Ranpariya
|
|
|
|
|
well the thing is....
fine u can access datagrid before using it. but before accessing any value from the grid it must contain something. fine i agree.
n as far as the second thing is concerned,
i find this way easy.
if u find, writing hundreds of lines of code, easy then there is no prob at all. i didn't say its wrong but for me atleast its tiring.
ne ways every buddy has his own logic and view. so wish u gud luck..
take carez
regards.
|
|
|
|
|
Hi,
You r right. Everybuddy has his own logic and view.
Good Luck to you too.
Thanks and Regards,
Chetan Ranpariya
|
|
|
|