Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > Web Development
You last visited: Today at 21:09

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



ASP.Net dynamisches Control ohne Placeholder

Discussion on ASP.Net dynamisches Control ohne Placeholder within the Web Development forum part of the Coders Den category.

Reply
 
Old   #1
 
-AmA-'s Avatar
 
elite*gold: 0
Join Date: Dec 2007
Posts: 728
Received Thanks: 460
ASP.Net dynamisches Control ohne Placeholder

Nun ich habe folgendes Problem.
Ich möchte ein Control, also z.B. ein Button dynamisch in ASP.Net erstellen.
Wie man dies mit den Placeholder Controls macht ist mir klar.
Nur ist es in meinem Fall nicht möglich da ich das Control in einem anderen Control will, welches nur HTML aus Ausgabe akzeptiert.
Ich habe schon nach Lösungen gesucht, hier ist mein aktueller Ansatz:

index.aspx:
HTML Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="index.aspx.cs" Inherits="DynamicButton.index" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <p>Normal Button:</p>
        <asp:Button runat="server" ID="normalButton" Text="Clickit" OnClick="normalButton_Click" />
        <p>Ergebnis:</p>
        <asp:Label runat="server" ID="normalLabel"></asp:Label>
    </div>
    <div>
        <p>Dynamic Button</p>
        <% = _testAusgabe %>
        <p>Ergebnis:</p>
        <asp:Label runat="server" ID="dynamicLabel"></asp:Label>
    </div>    
    </form>
</body>
</html>
PHP Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Web.UI.HtmlControls;

namespace 
DynamicButton
{
    public 
partial class index System.Web.UI.Page
    
{
        protected 
string _testAusgabe;

        protected 
void Page_Load(object senderEventArgs e)
        {
            
Button pageinpage = new Button();
            
pageinpage.Text "Clickit2";
            
pageinpage.ID "pageinpageButton";
            
pageinpage.Click += new EventHandler(pageinpage_Click);
            
_testAusgabe RenderControlOnPage(pageinpagetrue);
        }

        protected 
void normalButton_Click(object senderEventArgs e)
        {
            
normalLabel.Text Path.GetRandomFileName();
        }

        protected 
void pageinpage_Click(object senderEventArgs e)
        {
            
dynamicLabel.Text Path.GetRandomFileName();
        }

        static 
string RenderControl(Control control)
        {
            
StringWriter tw = new StringWriter();

            
Html32TextWriter writer = new Html32TextWriter(tw);
            
control.RenderControl(writer);
            
writer.Close();

            return 
tw.ToString();
        }

        static 
string RenderControlOnPage(Control controlbool useDynamicPage)
        {
            if (!
useDynamicPage)
                return 
RenderControl(control);

            const 
string STR_BeginRenderControlBlock "<!-- BEGIN RENDERCONTROL BLOCK -->";
            const 
string STR_EndRenderControlBlock "<!-- END RENDERCONTROL BLOCK -->";

            
StringWriter tw = new StringWriter();
      
            
Page page = new Page();
            
page.EnableViewState false;

            
HtmlForm form = new HtmlForm();
            
form.ID "__t";
            
page.Controls.Add(form);
            
form.Controls.Add(new LiteralControl(STR_BeginRenderControlBlock));
            
form.Controls.Add(control);
            
form.Controls.Add(new LiteralControl(STR_EndRenderControlBlock));

            
HttpContext.Current.Server.Execute(pagetwtrue);

            
string Html tw.ToString();

            
int at1 Html.IndexOf(STR_BeginRenderControlBlock);
            
int at2 Html.IndexOf(STR_EndRenderControlBlock);
            if (
at1 > -&& at2 at1)
            {
                
Html Html.Substring(at1 STR_BeginRenderControlBlock.Length);
                
Html Html.Substring(0at2 at1 STR_BeginRenderControlBlock.Length);
            }

            return 
Html;
        }
    }

Eigentlich ist es ja klar, das der nicht funktionieren kann. Schliesslich wird der dynamische Button quasi in einer eigenen Umgebung mit eigenem Viewstate und Eventvalidation erstellt.
Aus diesem Grund, wird das Event auch nicht ausgeführt.
Mein Ansatz, kann aber (hoffentlich) nicht komplett falsch sein.

Schon mal Danke für jegliche Hilfe, Ansätze und Kommentare...
-AmA- is offline  
Old 06/16/2013, 18:31   #2


 
MrSm!th's Avatar
 
elite*gold: 7110
Join Date: Jun 2009
Posts: 28,902
Received Thanks: 25,407
Arrow General Coding -> Web Development

#moved
MrSm!th is offline  
Reply


Similar Threads Similar Threads
[Trading] Placeholder for Tf2 Items for E*Gold
04/17/2013 - Trading - 1 Replies
This is a Placeholder for the user: http://www.elitepvpers.com/forum/members/5134740-z umbawumbas.html We want to trade 100 E*Gold for 2 Treasure Keys for the Game Team Fortress 2. If he answered to this Thread with "Yes" he accept the Trade, and send a Trade-Request to myself.
Dynamisches PNG durch PHP
01/21/2013 - Web Development - 9 Replies
Hallo, ich habe eine frage oder auch mehrere :). Ich möchte ein Dynamisches PNG erstellen, sozusagen eine Dynamische Signatur. Mein Code bis jetzt... <?php
[1.9.433] Server Control Hack. (Control every players life in your room !!)
08/21/2012 - Call of Duty Hacks, Bots, Cheats & Exploits - 46 Replies
Features: -Force Host -Change Max Players in lobby -Activate / De-Activate Godmode for every player in the room (Lets you survive anything, EVEN enemy MOAB's !) -Give unlimited ammo / Take ALL Ammo of every player in the room (Take all their ammo, leaving them nothing but a knife !) How To:
Dynamisches Captcha in eine Picture Box
06/03/2012 - .NET Languages - 9 Replies
Guten Tag. Ich probiere momentan ein bisschen mit HTTPWebrequest rum und scheitere beim laden in die Picturebox. Erlich gesagt, weiß ich nicht, wie ich das anstellen muss. Ich weiß nur das ich was mit RegEx machen muss. Diese Website ist mein locales WBB Forum. Quelltext: <div class="formFieldDesc"> <p>Bitte geben Sie die untenstehenden Zeichen ohne Leerstellen in das leere Feld ein. Groß- und Kleinschreibung müssen nicht beachtet werden. Sollten Sie das Bild auch nach mehrfachem...
ControlClick ohne Control-Daten?
10/27/2011 - AutoIt - 10 Replies
Hallo, ich habe ein programm welches keine auslesbaren Control-parameter besitzt. Wie kann ich in diesem Programm auf ein button klicken, wenn dieses im Hintergrund läuft? Das Programm befindet sich sonst immer auf der gleichen Stelle am Bildschirm, sodass es mit MouseClick kein problem war. Wie kann ich es jetzt mit Control Click machen? Hier mein Skript (lädt eine Datei in einem Programm) mit "MouseClick":



All times are GMT +1. The time now is 21:11.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.