Showing posts with label element. Show all posts
Showing posts with label element. Show all posts

Saturday, March 31, 2012

Server Side FieldSet?

I'm trying to write a Web Custom control that allows me to generate a set of server side text boxes inside the fieldset element. What I have is this:

protectedoverridevoid Render(HtmlTextWriter output)

{

StringBuilder sb =new StringBuilder();

//Begin the FieldSet if it's needed

if (this.ShowBorder )

sb.Append(string.Format("<fieldset style='WIDTH: {0}; HEIGHT: {1}'><legend>{2}</legend>",this.Width,this.Height,this.Legend));

//Add user controls

for(int i = 0; i <this.SearchFormFields.Length; i++)

{

SearchField curField =this.SearchFormFields[i];sb.Append(string.Format("<span class='fwifont'>{0}</span><br>", curField.Title));

//sb.Append(string.Format("<FWI:MultiRangeTextBox CssClass='fwifont' id=AccountNumberBox runat='server' TermName='{0}'></FWI:MultiRangeTextBox>", curField.TermName));

sb.Append("<asp:TextBox Runat='server' ID='fsdfd'></asp:TextBox>");

}

sb.Append("<br>");

//Finish off fieldset

if (this.ShowBorder )

sb.Append("</fieldset>");

sb.Append("<br>");

output.Write(sb.ToString());

}

However, the asp:text box does not render or show up. I'm guessing this has something to do with the fact that it's a server side control itself. Does anyone have any ideas on what I'm doing wrong here?

You are trying to output ASP control tags as markup. Would something like "<input type="text" id=......" rather the the ASP textbox control be more suitable?

Ta


Most unfortuantely, no, I cannot use html input fields. And actually, it not only needs to be a server side control, in reality it should be a custom web control that actually extends the asp:textbox class. I have a method that traverses all the controls on the web forms and handles the input of each textbox based on what "type" of server side text box it is.

Server side Event handler for DIV click?

Is it possible with ASP.NET C# to establish a click event on a DIV element so that when the user clicks on the DIV it can postback to the server and initate a click event for that DIV element? I am currently wrapping my content with a <A runat=server> to achieve the onserverclick effetc.

In fact if i wanted to create a server side event hanler for dynamic content, how would one go about establishing this. I can see .NET makes heavy use of __doPostBack on the client side but i just dont see how it can initate an event handler on the server side.

Tx

Hi quantass0,

You can handle the click event on a DIV as the code following (div1 is the id of the DIV element)

public

partialclass_Default : System.Web.UI.Page,IPostBackEventHandler

{

protectedvoid Page_Load(object sender,EventArgs e)

{

div1.Attributes[

"onclick"] = ClientScript.GetPostBackEventReference(this,"ClickDiv");

}

protectedvoid Div1_Click()

{

// Do something

}

#region

IPostBackEventHandler Memberspublicvoid RaisePostBackEvent(string eventArgument)

{

if (!string.IsNullOrEmpty(eventArgument))

{

if (eventArgument =="ClickDiv")

{

Div1_Click();

}

}

}

#endregion

}

Hope this helps


Excellent info. Thank you!

Hi, i wonder if you could help me, i'm trying to get this work inside a user control. It doesnt implementSystem.Web.UI.Page,

i have tried the followng code but i cant pick up the event

Sorry, this is converted to vb as well

Code behind is

Imports System.ReflectionPartialClass editControllerBarInherits System.Web.UI.UserControlImplements IPostBackEventHandlerProtected Sub Page_Load(ByVal senderAs Object,ByVal eAs EventArgs) cancelDiv.Attributes("onclick") =Me.Page.ClientScript.GetPostBackEventReference(Me,"ClickDiv")End Sub Protected Sub Div1_Click()' Do somethingEnd Sub Private MembersAs IPostBackEventHandlerPublic Sub RaisePostBackEvent1(ByVal eventArgumentAs String)Implements System.Web.UI.IPostBackEventHandler.RaisePostBackEventIf Not String.IsNullOrEmpty(eventArgument)Then If eventArgument ="ClickDiv"Then Div1_Click()End If End If End Sub

the div on the user control looks like this

 <div class="btnCancel" runat="server" id="cancelDiv"> </div>
 
could you help please?