| |

VerySource

 Forgot password?
 Register
Search
Author: gluttony

Ask about the user control to pass values ​​to the aspx page

[Copy link]

0

Threads

73

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 China

Post time: 2020-1-21 18:36:01
| Show all posts
Is there a control for myascx in your index.aspx?
such as:
<uc1: test id = myascx runat = server />
Reply

Use magic Report

0

Threads

4

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-21 22:45:01
| Show all posts
Learn
Reply

Use magic Report

1

Threads

16

Posts

12.00

Credits

Newbie

Rank: 1

Credits
12.00

 China

Post time: 2020-1-23 11:54:01
| Show all posts
mark
Reply

Use magic Report

1

Threads

9

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

 Author| Post time: 2020-1-26 11:27:01
| Show all posts
zhouji700Yes, I drag to index.aspx to open the index.aspx point ascx to perform a search
Reply

Use magic Report

0

Threads

73

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 China

Post time: 2020-1-27 12:18:01
| Show all posts
Khan, not done yet? Let me give you an example, a total of four files, you copy to VS and compile:
my.ascx:
<% @ Control Language = "c #" AutoEventWireup = "false" Codebehind = "my.ascx.cs" Inherits = "test.my" TargetSchema = "http://schemas.microsoft.com/intellisense/ie5"%>
<asp: TextBox id = "TextBox1" runat = "server"> a4w </ asp: TextBox>

my.ascx.cs:
namespace test
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

/// <summary>
/// My summary description.
/// </ summary>
public class my: System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.TextBox TextBox1;

public string Retu1 {
get {
return this.TextBox1.Text;
}
set {
this.TextBox1.Text = value;
}
}

private void Page_Load (object sender, System.EventArgs e)
{
// Place user code here to initialize the page

}

#region Web Form Designer Generated Code
override protected void OnInit (EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Forms designer.
//
InitializeComponent ();
base.OnInit (e);
}
Ranch
/// <summary>
/// Designer supports required methods-don't use code editor
/// Modify the content of this method.
/// </ summary>
private void InitializeComponent ()
{
this.Load + = new System.EventHandler (this.Page_Load);

}
#endregion
}
}

webform1.aspx:
<% @ Page language = "c #" Codebehind = "WebForm1.aspx.cs" AutoEventWireup = "false" Inherits = "test.WebForm1"%>
<% @ Register TagName = "abc" TagPrefix = "my" src = "my.ascx"%>
<! DOCTYPE HTML PUBLIC "-// W3C // DTD HTML 4.0 Transitional // EN">
<HTML>
<HEAD>
<title> WebForm1 </ title>
<meta name = "GENERATOR" Content = "Microsoft Visual Studio .NET 7.1">
<meta name = "CODE_LANGUAGE" Content = "C #">
<meta name = "vs_defaultClientScript" content = "JavaScript">
<meta name = "vs_targetSchema" content = "http://schemas.microsoft.com/intellisense/ie5">
</ HEAD>
<body>
<form id = "Form1" method = "post" runat = "server">
<my: abc id = "myAscx" runat = "server" /> <FONT face = "宋体"> <BR>
</ FONT>
<asp: Button id = "Button1" runat = "server" Text = "Button"> </ asp: Button>
</ form>
</ body>
</ HTML>

webform1.aspx.cs:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using ICSharpCode.SharpZipLib.BZip2;

namespace test
{
/// <summary>
/// A summary description of WebForm1.
/// </ summary>
public class WebForm1: System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button Button1;
protected test.my myAscx;
private void Page_Load (object sender, System.EventArgs e)
{
// read the value of the control below
Response.Write (myAscx.Retu1);
}

#region Web Form Designer Generated Code
override protected void OnInit (EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Forms designer.
//
InitializeComponent ();
base.OnInit (e);
}
Ranch
/// <summary>
/// Designer supports required methods-don't use code editor to modify
/// The contents of this method.
/// </ summary>
private void InitializeComponent ()
{
this.Button1.Click + = new System.EventHandler (this.Button1_Click);
this.Load + = new System.EventHandler (this.Page_Load);

}
#endregion

private void Button1_Click (object sender, System.EventArgs e)
{
// Set the value of the control below
myAscx.Retu1 = "ddd";
}

}
}
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-2-22 13:30:01
| Show all posts
up
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-5-25 21:45:01
| Show all posts
MARK
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list