How to work with Usercontrolls in Asp.net and how to load the data from a website?

Brawler420 1 Reputation point
2022-06-19T20:54:42.127+00:00
<%@ Page Title="Weather Data" Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WeatherWeb._Default" %>  
  
<!DOCTYPE html>  
<html xmlns="http://www.w3.org/1999/xhtml">  
<head runat="server">  
    <title>Weather Data</title>  
</head>  
<body>  
    <form name="form1" runat="server">  
        <div>  
            <asp:Calendar runat="server" ID="startCalendar"></asp:Calendar>  
            <br />  
            <asp:Calendar runat="server" ID="endCalendar"></asp:Calendar>  
            -- autopostback="true"  
            <asp:Button runat="server" ID="submitButton" Text="Submit" OnClick="SubmitButton_OnClick" />  
        </div>  
        <div>  
            <asp:Table runat="server" BorderWidth="3" ID="WeatherTable">  
                <asp:TableHeaderRow>  
                    <asp:TableHeaderCell Text="ID"></asp:TableHeaderCell>  
                    <asp:TableHeaderCell Text="Datum"></asp:TableHeaderCell>  
                    <asp:TableHeaderCell Text="Zeit"></asp:TableHeaderCell>  
                    <asp:TableHeaderCell Text="Temperatur"></asp:TableHeaderCell>  
                    <asp:TableHeaderCell Text="Luftdruck"></asp:TableHeaderCell>  
                    <asp:TableHeaderCell Text="Regen"></asp:TableHeaderCell>  
                    <asp:TableHeaderCell Text="Wind"></asp:TableHeaderCell>  
                    <asp:TableHeaderCell Text="Richtung"></asp:TableHeaderCell>  
                    <asp:TableHeaderCell Text="Feuchtigkeit"></asp:TableHeaderCell>  
                </asp:TableHeaderRow>  
            </asp:Table>  
        </div>  
    </form>  
</body>  
</html>  

ServiceReference1.Service1Client client = new ServiceReference1.Service1Client();  
protected void Page_Load(object sender, EventArgs e)  
        {  
            if (StoreList.Items.Count == 0)  
            {  
                foreach (var store in client.GetStores())  
                {  
                    StoreList.Items.Add(store.Name);  
                }  
            }  
        }  
protected void SubmitButton_OnClick(object sender, EventArgs e)  
        {  
            DateTime start = startCalendar.SelectedDate;  
            DateTime end = endCalendar.SelectedDate;  
            Table table = WeatherTable;  
            foreach (var item in client.GetWeatherBetween(start, end))  
            {  
                TableRow row = new TableRow();  
                TableCell idCell = new TableCell  
                {  
                    Text = item.ID.ToString()  
                };  
                TableCell datumCell = new TableCell  
                {  
                    Text = item.Datum.ToString()  
                };  
                TableCell zeitCell = new TableCell  
                {  
                    Text = item.Zeit.ToString()  
                };   
                TableCell temperaturCell = new TableCell  
                {  
                    Text = item.Temperatur.ToString()  
                };   
                TableCell luftdruckCell = new TableCell  
                {  
                    Text = item.Luftdruck.ToString()  
                };   
                TableCell regenCell = new TableCell  
                {  
                    Text = item.Regen.ToString()  
                };   
                TableCell windCell = new TableCell  
                {  
                    Text = item.Wind.ToString()  
                };  
                TableCell richtungCell = new TableCell  
                {  
                    Text = item.Richtung.ToString()  
                };  
                TableCell feuchtigkeitCell = new TableCell  
                {  
                    Text = item.Feuchtigkeit.ToString()  
                };  
                row.Cells.Add(idCell);  
                row.Cells.Add(datumCell);  
                row.Cells.Add(zeitCell);  
                row.Cells.Add(temperaturCell);  
                row.Cells.Add(luftdruckCell);  
                row.Cells.Add(regenCell);  
                row.Cells.Add(windCell);  
                row.Cells.Add(richtungCell);  
                row.Cells.Add(feuchtigkeitCell);  
                table.Rows.Add(row);  
            }  
        }  
    }  

How can I use UserControlls with asp.net with this example now. This is my only code in asp.net my backend is a wcf and i also wanted to ask how to get the Data not from a Database but from a URL any suggetions?

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,372 questions
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,254 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Lan Huang-MSFT 25,551 Reputation points Microsoft Vendor
    2022-06-20T03:28:23.823+00:00

    Hi @Brawler420 ,

    How can I use UserControlls with asp.net with this example now.

    You create ASP.NET user controls in much the same way that you design ASP.NET Web pages. You can use the same HTML elements and controls on a user control that you do on a standard ASP.NET page. However, the user control does not have html, body, and form elements; and the file name extension must be .ascx.
    You can check the documentation for the specific creation steps.
    https://learn.microsoft.com/en-us/previous-versions/aspnet/wt3k2fyw(v=vs.100)
    ![212775-image.png

    You can call UserControl in web page.When you drag a UserControl onto a page. You can see this code.
    212796-image.png

    how to get the Data not from a Database but from a URL any suggetions?

    Do you want to implement it via wcf or asp.net?
    Asp.net You can do it with QueryString.
    https://learn.microsoft.com/en-us/dotnet/api/system.web.httprequest.querystring?view=netframework-4.8

    WCF You can do it with UriTemplate.
    https://learn.microsoft.com/en-us/dotnet/framework/wcf/feature-details/uritemplate-and-uritemplatetable
    https://learn.microsoft.com/en-us/dotnet/framework/wcf/feature-details/wcf-web-http-programming-model-overview
    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments