| |

VerySource

 Forgot password?
 Register
Search
View: 734|Reply: 7

How to load controls dynamically with ajax

[Copy link]

1

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-1-19 18:00:01
| Show all posts |Read mode
[Ajax.AjaxMethod ()]
public void CreateDownList (string id, string ddlName)
{
PlaceHolder1.Controls.Add (control);
}

Failure, how can I make him effective
Reply

Use magic Report

0

Threads

3

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-26 21:00:02
| Show all posts
I do not know:(
Reply

Use magic Report

0

Threads

64

Posts

35.00

Credits

Newbie

Rank: 1

Credits
35.00

 China

Post time: 2020-1-27 18:36:01
| Show all posts
Haven't used your kind, and I try not to answer ajax for the time being. However, if you find a solution yourself, the key is: the server sends the html string obtained by the control Render to the client, and then the client uses this html to update the control's performance (such as using the OuterHtml attribute).

In fact, if you want to develop interactive ajax applications, you must also consider how to manage the tens of thousands of state information of the control, and how to avoid the server-side always rebuilding the page object (when emphasizing the smooth and detailed operation experience, The original web page reconstruction mechanism is really too slow).
Reply

Use magic Report

0

Threads

17

Posts

14.00

Credits

Newbie

Rank: 1

Credits
14.00

 China

Post time: 2020-1-27 18:54:01
| Show all posts
The background event called by ajax cannot call the server control.
So the landlord wrote: PlaceHolder1.Controls.Add (control);
Of course something went wrong.
Reply

Use magic Report

1

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-1-27 21:18:01
| Show all posts
pyonus, I also read some online instructions. I am vaguely aware that this will make mistakes. May I ask, how can I solve this situation, or give me some directions, and where should I find the reason
Reply

Use magic Report

1

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-1-27 23:36:01
| Show all posts
saintfrosty, I'm not very deep in learning .net, I don't understand a lot of the principles, otherwise I can post the original code and give me some directions.

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ajax;
using ZhuJi.Common;
using ZhuJi.Facade;
using Globals = ZhuJi.Resources.Globals;

namespace ZhuJi.Web
{
/// <summary>
/// Summary description of WebForm2.
/// </ summary>
public class WebForm2: Page
{
protected PlaceHolder PlaceHolder1;

private void Page_Load (object sender, EventArgs e)
{
Utility.RegisterTypeForAjax (typeof (WebForm2));
CreateDownList ("0", "ddl0");
}

[AjaxMethod ()]
public void CreateDownList (string id, string ddlName)
{
PlaceHolder1.Controls.Add (EventControls.CreateControl ("System.Web.UI.WebControls.DropDownList", ddlName));
DropDownList ddl = (DropDownList) FindControl (ddlName);
Category category = new Category ();
string whereValue = string.Concat ("ParentId =", id);
ddl.DataSource = category.ListAll (whereValue, "Path");
ddl.DataTextField = "Title";
ddl.DataValueField = "Id";
ddl.DataBind ();
ddl.Items.Insert (0, new ListItem (Globals.ResMan ("Category.Root"), id));
ddl.Attributes.Add ("onChange", "LoadCategory (this)");
}

#region Web Form Designer Generated Code

protected override void OnInit (EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Forms designer.
//
InitializeComponent ();
base.OnInit (e);
}

/// <summary>
/// Designer supports required methods-don't use code editor to modify
/// The contents of this method.
/// </ summary>
private void InitializeComponent ()
{
Load + = new EventHandler (Page_Load);
}

#endregion
}
}
Reply

Use magic Report

0

Threads

64

Posts

35.00

Credits

Newbie

Rank: 1

Credits
35.00

 China

Post time: 2020-1-28 15:18:01
| Show all posts
Your code is useless. According to the points I said, google it yourself, what is the render of the asp.net control, how to get html through it, and the outerHtml or innerHtml of dhtml.
Reply

Use magic Report

1

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-1-29 13:45:02
| Show all posts
saintfrosty, thank you for giving me directions
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