p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 2.0 Professional (http://p2p.wrox.com/forumdisplay.php?f=215)
-   -   Access input controls generated by Client Script (http://p2p.wrox.com/showthread.php?t=67367)

vinod_yadav1919 April 13th, 2008 02:13 AM

Access input controls generated by Client Script
 
 how to access input controls in "asp net" 2.0 generated by client side scripts

e.g onclick of the button will automatically add some textboxes (from client side) ,so that user can enter multiple entries,now I want to access those textboxes values .

i tried something in Code behind file
string newval=Request.Form["txtBox"+i];
where i is any number.
Any input or pointer would be highly appreciated!!







Cheers :)

vinod

planoie April 13th, 2008 11:52 AM

What happened when you tried that? Presumably it didn't work, otherwise you wouldn't be posting here. So how did it not work?

-Peter
peterlanoie.blog

vinod_yadav1919 April 14th, 2008 05:11 AM

Hi Peter!!
I am able to figure it out but still thinking abt it!!

<input type="text" id="activeCategory" value="0" />
<input type="button" onclick="addMoreRows()" id="myBtn" value="AddMore" />

addMoreRows() function is client side javascript function that add one row with input type=text.
and at the same time it increments the activeCategory value to activeCategory+1;
id of the input control txtBox1,for next time it would be txtBox2 ;


When serverside i used the following code
 string str = Request.Form["activeCategory"];
it returns only "0" which was previously set.


int totalCount=Convert.ToInt32(Request.Form["activeCategory"]);
or
int totalCount=Convert.ToInt32(activeCategory.Text);//since now it is aspx textbox control.

int i;
for(i=1;i<=totalCount;i++)
{
string newval=Request.Form["txtBox"+i];
//Unable to retrieve in previous scenario with html Control, since control is not transferred into for loop because of the value of activeCategory=0
}


Well I was able to figure out..
Solution- <asp:TextBox ID="activeCategory" runat="server"></asp:TextBox>

Client/Customer want the solution and we achieved it.Still I am thinking...

1>I don't want aspx server control that will create on the server side and expose its properties and methods.

2>When i use normal HTML control and by client side script increment it's values ,why I am not able to get current value(incremented value),rather than I am always getting 0 value.
On the other hand for dynamic created textbox using javascript,I am getting value e.g.Request.Form["txtBox"+i] has value


e.g <Design time html Control>
  <form id="form1" runat="server">
      <input type="text" id="txtBox1" />
    <input type="text" id="txtBox2" />
    <input type="text" id="txtBox3" />
    <input type="text" id="txtBox4" />
      </form>
   We do not get the value of txtBox1,2,3,4 using
either Request.Form["txtBox1"] or
string newval=Request.Form["txtBox"+i]; //where i=1,2,3;

<html Control-Using Client Side>
But when we create dynamic input using javascript on the client side I am getting the value
Request.Form["txtBox1"] or
string newval=Request.Form["txtBox"+i]; //where i=1,2,3;


3>Please do correct me if i think "normal HTML control is light weight than HTML Server Control/Web Server(aspx) Control"


Cheers :)

vinod

planoie April 14th, 2008 08:33 PM

Can you post the client side code you are using to add the control and update the text box value?

3> Any HTML in your ASPX markup that is not a server control will be seen as just literal text. If you looked at the page's control tree, you would see a Literal class control in the sequence of controls between your server controls. So, yes, to a certain extent plain HTML may be lighter, but in the grand scheme of things, it probably doesn't make much of a different. In the end you still have some control, whether it's a server-textbox or just literal text.

-Peter
peterlanoie.blog


All times are GMT -4. The time now is 09:06 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.