0

I have a Application I neaver work on Web Form so simple I have to send a data to html page..

in the First page I have a Button and a listBox

<asp:Button ID="Button12" runat="server" Text="Button" OnClick="Button12_Click" />
<asp:ListBox ID="ListBox1" runat="server"></asp:ListBox>

So when I click the button it should send list of user to the list box

protected void Button12_Click(object sender, EventArgs e)
{
    ApplicationDbContext obk = new ApplicationDbContext();
    foreach (var item in obk.Users.ToList())
    {
        ListBox1.Text = item.UserName;

    }

First it is not showing the data in the list box

second I want to send a data from C# to Html like in MVC we have ViewData["jsad"] so is there any thing in Web Form I am new in Web Forms I work on MVC so I am so confuse

And you can give me any good web link for tutorial for Web form ,

2
  • Wow!How can you work on MVC without the knowledge of webforms? Commented Oct 22, 2015 at 0:39
  • Because I never work on Web Form i work on Ruby on rail which use is MVC then i learn Asp.net mvc with in 10 days but cant able to figure out this Web Form ...Actually what i am trying to do is to assignee some data to a ViewData or TEmpData and return that to the HTml page Commented Oct 22, 2015 at 1:15

1 Answer 1

1

First you have to add ListItem to show item.UserName in your ListBox.

protected void Button12_Click(object sender, EventArgs e)
{
    ApplicationDbContext obk = new ApplicationDbContext();
    foreach (var item in obk.Users.ToList())
    {
        ListBox1.Items.Add(item.UserName);
    }
}

Secondly, I think Page.Items is very equivalent to ViewData. It's IDictionary so you can add and show the value of "jsad" like this.

aspx.cs:

protected void Page_Load(object sender, EventArgs e)
{
    Page.Items["jsad"] = "value";
    // or Page.Items.Add("jsad", "value");
}

aspx:

<div>jsad = <%: Page.Items["jsad"] %></div>

and here is a good reference for MVC developers to understand WebForms. http://www.codeproject.com/Articles/528117/WebForms-vs-MVC

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

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.