0

I have made an application in javascript using HTML fields in asp.net, as asp text boxes were disturbing the ids, so i used html fields, which are working fine with javascript, now i want to fetch database table columns on page load, and want to assign to html fields, what is the best way to do so? Help me!!!!

4 Answers 4

2

You could go back to using the ASP TextBoxes and access the ids in JavaScript as follows:

<%= IDofTextBox.ClientID %>

It's probably the easiest as naturally they can then be accessed in the code behind very easily.

Sign up to request clarification or add additional context in comments.

5 Comments

runat server changes the id, can i write sql code in asp, by including System.Data.SqlClient, is there any help for that, how to do it.
why are u wanting to use code in .aspx page? you can do with codebehind also
I cannot access HTML textfield from code behind, i can just read it, not write it. And i cannot use Textbox, cannot change to textboxes or anything else.
you can create globle public string variables in codebehind and assign value to them and attach with server tag like e.g. <input type="text" value='<%= Studentname%>'>
Thanks , i have made class level variables, and my work got done :)
1

you can use asp text boxes fine if you grab a reference in your javascript to their asp.net generated ID via <%= textboxname.ClientId %>

2 Comments

How can i include System.Data.SqlClient in asp page, and write database code in asp page, i have made a very big application, cant do what you suggest, but get me rid of this issue now please.
you can reference this sql class library if you need it just use "add reference" to your web project and then add it to your code behind in a using clause - you can put database code in code behind if you really want to - i wouldnt recommend it but its your call.
1

This is not the right way to do it (I wouldn't recommending it), but if its what you need, then it will work.

Add method="post" action="<your path here>" to your form element and when the submit button posts, you will be able to access all the form variables like so:

string txtName = Request["TextBox1"] ?? string.Empty; //replace textbox 1 with text box name

Just be sure to replace the action in form to your page etc..

But really, going back to <asp:TextBox... will save you a lot more time and as Ian suggested, you can access them with javascript by the server tags <%= TextBox1.ClientId %>

ps: also, the ?? is a null coalesce character. its a short form of saying

if(Request["textbox1"] != null)
    txtName = Request["textbox1"];
else
    txtName = "";

Comments

0

If I understand you correctly. You just need to add runat="server" and id="someName" to the html fields and access them in the code behind by its given id.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.