asp.net textbox to html page data - c#

Hi I'm a bit rusty with this again, I have a user profile web page and I'm working on making a wall posting system, I can do it the crappy n easiest way: textbox to listbox and then save the listbox as a text document for retrieval when the client logs in again.
But id like to write it to the HTML code or something of that nature. Like those div containers so my style sheet is applied to the data being posted.
Could anyone give me a head start to this?

You know from where you need to copy (sorry... take inspiration) your functionality.
Have a text box
User submits the data...
Add it to DB and either return the same data and add new table row below the previous one
or just on client add extra "TR" below the previous "TR".
It will require jQuery or any other similar thing. You have SO, dissect it using Firebug and build your own version of it.

You can do this with jQuery
$('button').click(function(){
var x = $('textarea').val();
$('div').html(x);
});
Check working example at http://jsfiddle.net/dzert/

Related

ASP.NET Code behind form rows

I'm trying add multiple items to a database table. I've created a form that will allow the user to add more form rows which include a dropdown and multiple input fields. New fields are generated when the user clicks on "+". This is developed using JavaScript.
It is easy to add an incremented value to an ID using JavaScript, but new rows are not made using the runat="server" so I am afraid my code behind won't see the values in the fields.
I want my code to loop through each form "row" and grab each item. Then take this data and insert it into a SQL database. How do I get that working?
I can give you some guides to continue from the point you are (and solve this question - so I am afraid my code behind won't see the values in the fields.)
a. You create your controls using java-script on the page.
b. User then is post them back, what you have all ready known, with some new controls that code behind didn't know about.
now the trick here is that you grab this return
HttpContext.Current.Request.Form
and analyse it to see whats "is new there", what are the new post controls that you don't know about - and then you create them on code behind again - and gets their input values.

Find Element IDs of HTML TextBox

I'm trying to build a very basic C# Forms application that manipulates an online form. The downside is, the website is pretty old school. I'm struggling to figure out how to 'point' to the textboxes of the website.
I'm trying to use:
webBrowser1.Document.GetElementById("PanelMain")...
But getting Null errors. When looking at the HTML of the site, its a lot of Divs inside Divs... Is there a way to list the available objects / document elements I can use?
For example, use this website. https://miscm.callmis.com/. How would I write the code to access the User Name text box to populate it with whatever string I want in C#?
I hope that makes sense - Thx
You would do the following to get access to the Username textbox of the provided page:
var userTextInput = webBrowser1.Document.GetElementById("Login1_UserName");
For accessing the iframe and if it is the only IFRAME on the page, you can do the following:
var userTextInput = webBrowser1.Document.Window.Frames[0].Document.GetElementById("Login1_UserName")

General concept regarding dynamic textboxes on the fly

I am working on a project which has a requirement to build "pages" on the fly. A page can consist of various controls like textboxes, checkbox etc. Currently when the user wants to add a new textbox I make a ajax request and render partial view and return the HTML and show it on client side. This works but I also want to handle the data properly when these dynamic controls are filled up by user. In a way if I am not wrong I need to be able to make array of HTML controls. Now if we give static List to our view and generate textboxes using Html.TextboxFor we see that the name generated is something:
[0].FruitName
[1].FruitName
[2].FruitName
How do I handle this index part when making a Jquery Ajax request so that I always get the correct indexes and render it on client.
If anybody has any better solution than making ajax request then also please let me know. I need to handle the dynamic rendering of HTML controls and also access their values properly when posted back to server.
Take a look at Non-Sequential Indices at http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx.
He introduced a helper method to generate it as well.
Also, I think you can just pass an index with your ajax call which then gets passed from Controller to your partial view and use it to generate a proper indexed TextBox.
Update:
I've asked a very similar question at Submit javascript dynamically added elements to controller method like Stackoverflow

list view problem with respect to my problem

I have a listview in wpf and i am swapping two items index..
the swapping must be visible to the user.
i tried giving thread delay..
it didnt work
How to do that..
If I was going to do this I would delete the list view and lock it up where you can't use it again. Then code whatever your list view was outputting in C# using whatever you use to query your database(I think LINQ to SQL is the most robust solution right now) and then use a string builder to construct the html. This way you can assign a id to each div and append an incrementing number to the end of the id. Finally you could write your javascript and use the id's. Here is a link that shows how to build a gridview without using a gridview control.
See the first answer to the question in this link: How to show pop up menu from database in gridview on each gridview row items?
I am not sure whether it will work for your problem or not.
I think you need some kind of animation there. If it is web project, you can use jQuery animation to do that.

Ways to detect changed account/no account found in ASP.NET/C#

I have an ASP.NET page where at the top of the page is a search box. There are 2 text boxes - one is an autocomplete extender for the Name on a database, and one is just inputting the ID.
The page features DetailsViews and GridViews primarily, and even when no account has been searched for, these display blank data which is not ideal. I sort of fixed this by using if (IsPostBack), encasing the elements in a placeholder and setting it to visible only if the page ispostback. But this doesn't cover if the user types in an incorrect ID.
Also, some accounts have huge amounts of data inside the GridView's. I had an issue where because I have no way of detecting when a data source's rows has changed, I end up binding whenever the page loads (Page_Load method). I've come to realise this is simply very bad - there are lots of times when the user can click various things in the page and have the page postback, and it takes an eternity to load each time I click something for accounts with lots of data.
Anyway, my question is essentially two-fold but I have a feeling the solution will be similar:
1: How can I detect when there are no accounts returned when searching, and disable the Grids/Detailsviews and show an error message?
2: How can I figure out when the user searches for another account and only rebind the grids after that has happened?
Thanks
This method is very ugly but it'll get the work done.
1) To Check whether there are no records; after the AutoComplete Extenders Webservice is called if no record is returned put some value in Session like
Session["NoData"]=true;
if Records are found then;
Session["NoData"]=false;
after the webservice is called do ajax request to check that session & on the basis of value do what you want.
2) You can achieve this also by following the above option.

Categories

Resources