Access value of Pure HTML, Html server control and asp.net server control on server side

ASP.NET provides their controls. It also provides to make html control server side. Also, we can use pure html control.Let’s discuss and compare practically.
Case I:
Suppose there are three textboxes(Pure HTML, HTML Server and Asp.NET) in following

<input type ="text" name="txtPureHTML" />
<input type="text" id="txtHTMLServer" runat="server" />
<asp:TextBox ID="txtASP" runat="server"></asp:TextBox>

If you see view source on runtime you will get

<input type ="text" name="txtPureHTML" />
<input name="txtHTMLServer" type="text" id="txtHTMLServer" />
<input name="txtASP" type="text" id="txtASP" />

And you can access on server side:

Response.Write(Request("txtPureHTML") & " " & Request("txtHTMLServer") & " " & Request("txtASP"))
OR
Response.Write(Request("txtPureHTML") & " " & txtHTMLServer.Value & " " & txtASP.Text)


Case II:
Now Create a Usercontrol and put these three textboxes in it and Drag usercontrol in form.
HTML View source will be

<input type ="text" name="txtPureHTML" />
<input name="WebUserControl1$txtHTMLServer" type="text" id="WebUserControl1_txtHTMLServer" />
<input name="WebUserControl1$txtASP" type="text" id="WebUserControl1_txtASP" />

And you can access on server side using request:
Response.Write(Request("txtPureHTML") & " " & Request("WebUserControl1$txtHTMLServer") & " " & Request("WebUserControl1$txtASP"))

Same for contenplaceholder If we use master page.
Conclusion:
1. Request works only for name attribute.
2. For Pure HTML control we must define name attribute and can access using name.
3. We can access textbox value on server side using following property
textBox1.Value (HTML Server textbox)
textBox1.Text (ASP.NET Server Control)

No comments:

Post a Comment