finding server control, in the code behind, created from client side using javascript

Hi experts

 

i wanna add server side controls using javascript and access it in code behind but i am not able to access it can u give me the solution

example

javascript file

function AddControl()

{

var table=document.createElement('table')

var tr=document.createElement('tr')

var cell1=document.createElement('td')

cell1.innerHtml='<input type="text" ID="txtSample" runat="server"/>

tr.appendChild(cell1)

table.appendChild(tr);

}

 

if i try to get this control in code behind like this i am not able to get

HtmlInputText txt=FindControl("txtSample") as HtmlInputText

 

advence thanks for your reply


Yasser
Spica.
www.spica.ae
www.bncnetwork.net
Please remember to mark as answers if this helps
0
shayas
2/6/2008 12:49:07 PM
asp.net.web-forms 93655 articles. 6 followers. Follow

12 Replies
1190 Views

Similar Articles

[PageSpeed] 0
Get it on Google Play
Get it on Apple App Store

 Try

HtmlInputText tb = (HtmlInputText)this.Page.FindControl("txtSample"); 

Response.Write(tb.Value); 


Regards,Vinz

"Code, Beer and Music" that's my way of being a programmer!

How to get your Forum Question Answered | Blog | CodeASP.NET
0
vinz
2/6/2008 1:05:45 PM

Dear vinz

i already tried this coz i am creating in the client side so server don't know what are the controls in it if it is created dynamically using serverside script then it will work


Yasser
Spica.
www.spica.ae
www.bncnetwork.net
Please remember to mark as answers if this helps
0
shayas
2/6/2008 1:10:02 PM

Hi,

try this one as i dont know whether its working for you or not.

dim str as string = Request.Form("txtSample")

or you can also try this one, define html control to control declaration section and try to get that one.like

dim txtSample as System.Web.UI.HtmlControls.HtmlInputText

try to access via txtSample.value, its working with .net 1.1 and i dont know whether its working with .net 2.0 or not.
 


Thanks n Regards,
Rajvir
Sr. Software Engg
0
rajvirzala
2/6/2008 1:13:21 PM

 Just be sure that the controls is rendered in the Page before accessing it... BTW when do you call that method for adding controls? was it in Button Click or something else?


Regards,Vinz

"Code, Beer and Music" that's my way of being a programmer!

How to get your Forum Question Answered | Blog | CodeASP.NET
0
vinz
2/6/2008 1:25:22 PM

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" EnableViewState="True">

<Columns>

<asp:BoundField DataField="projectname" HeaderText="Project" />

<asp:BoundField DataField="projectid" HeaderText="ProjectID" />

</Columns>

</asp:GridView>

</div>

<input type=button id="ADD" onclick="javascript:NewRow('<%=GridView1.ClientID %>','<%=tblDetails.ClientID %>')" value="Add New"/>

this is sample code when i click the html button it will create a new row in the gridview with asp:text for each column i wanna add several rows like that after submitting that i need to get those values in code behind i am not able to find the control in the code behind

 


Yasser
Spica.
www.spica.ae
www.bncnetwork.net
Please remember to mark as answers if this helps
0
shayas
2/6/2008 1:29:50 PM

Since it is placed inside gridview then you need to access each rows in gridview something like

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {

        if (e.Row.RowType == DataControlRowType.DataRow)
        {

            HtmlInputText tb = (HtmlInputText)e.Row.FindControl("txtSample");
            string str = tb.Value;
        }
    } 

 


Regards,Vinz

"Code, Beer and Music" that's my way of being a programmer!

How to get your Forum Question Answered | Blog | CodeASP.NET
0
vinz
2/6/2008 2:01:03 PM

hi vinz thank u for ur reply but

i already tried this but it won't as i already said the datarow will bound according to the datasource not the rows that are created in client side

so still the problem is not solved


Yasser
Spica.
www.spica.ae
www.bncnetwork.net
Please remember to mark as answers if this helps
0
shayas
2/6/2008 2:06:38 PM

 I have few questions here.. does the mehtod AddControls really add those controls in the Grid? if so then how was the control created in the grid? is it a boundcolumn fields or a template fields?


Regards,Vinz

"Code, Beer and Music" that's my way of being a programmer!

How to get your Forum Question Answered | Blog | CodeASP.NET
0
vinz
2/6/2008 2:15:12 PM

Hi vinz

It is not bound column as i already posted javascript on my post it just get the id of grid view as table and it adds row to it and the rows contain textbox


Yasser
Spica.
www.spica.ae
www.bncnetwork.net
Please remember to mark as answers if this helps
0
shayas
2/7/2008 4:37:41 AM

anyone help me


Yasser
Spica.
www.spica.ae
www.bncnetwork.net
Please remember to mark as answers if this helps
0
shayas
2/11/2008 6:17:00 AM

can anyone help in this


Yasser
Spica.
www.spica.ae
www.bncnetwork.net
Please remember to mark as answers if this helps
0
shayas
2/11/2008 8:26:10 AM

is there any expert to answer this


Yasser
Spica.
www.spica.ae
www.bncnetwork.net
Please remember to mark as answers if this helps
0
shayas
2/13/2008 5:18:27 AM
Reply: