It looks to me that the ASP.Net PlaceHolder control doesn't emit any HTML, and therefore can't be used by clientside javascript or JQuery to add items to the PlaceHolder. Does anyone know of a way around this limitation, or of an ASP.Net control that can be used to dynamically add items by client side code?
That is very true. Anyway, JavaScript cannot add controls to the PlaceHolder, only insert elements in its place.
You can use a client side <div></div>, or a Panel - they will all have the effect you're looking for.
Related
i am at starter level in asp.net i was developing a small application just to add students to database, main reason was to use update panel but when I use AsyncPostBack trigger the dropdown box does not render properly but with normal PostBack it does I am assuming i am missing out something the code has nothing special i just used and inside and here is an image that can describe it better
here is a link screenshot of what's happening : http://imageshack.us/photo/my-images/842/dfpw.png/
Are you using any Jquery plugin to make normal dropdownlist as fancy as looking in the screenshot attached.. if that is the case call the same plugin in the pageLoad() function too as after partial postback happens, the dropdown looses it's appearance and looking like normal dropdownlist.
In my C# asp.net 3.5 web application I am having controls like div tag inside that one textbox and one check box and the page is having a submit button. So in this submit button click I want to make the controls inside the div tag visible.. I am calling a JQuery function to do this. All the statements are getting executed but the control is not visible..
Following is the code in my JQuery function
$("input[name$='QuestionAndAnswerEditorDiv']").show();
$("input[name$='answerLabel1']").show()
$("input[name$='wmd-AnswerTextBox']").show()
My div tag and its controls in the user control page are like the following
<div id="QuestionAndAnswerEditorDiv" runat="server">
<div id="wmd-button-bar" class="wmd-panel wmd-button-row"></div>
<textarea name="QuestionandAnswerTextArea" runat="server" id="AnswerTextBox" onkeyup="prettyPrint();" class="wmd-input editor" cols="92" rows="15"/><div class="wmd-preview text-preview preview" style="-ms-word-wrap: break-word;"></div>
As I noticed these controls are make visible=false in another page so they are not coming in the page source.. So Let me know how to work these controls now
all web server controls in asp.net < 4 are not rendered using their given name.
to use the rendered name use Control.ClientID
Setting QuestionAndAnswerEditorDiv.Visible = false; will mean that it doesn't get rendered to the page. In your code behind do the following:
QuestionAndAnswerEditorDiv.Attributes.Add("style", "display:none");
QuestionandAnswerTextArea.Attributes.Add("style", "display:none");
the JQuery show() function uses the display property and will set it to "block", which will make it visible.
This may not work because div is not going to render as input element and label is rendered as span element in asp.net so check for the type of controls
for div
$("div[name$='QuestionAndAnswerEditorDiv']").show();
for label
$("span[name$='answerLabel1']").show()
for textbox
$("input[name$='wmd-AnswerTextBox']").show()
Edit :
so as i suggested in my answer make use of proper jquery selctor so that this will work for you
Edit 1
So rather than making control visible= false set there sytles to disply:none so that controls avaialbe on you page and you can play with them using jquery/javascript
I noticed that the
asp:Button
for example will work without javascript enabled in the browser. However any other control with an "OnClick" or "OnServerClick" event must use the javascript_doPostback.
Are there any controls besides the Button that don't need to use javascript?
I want to know because I want to be able to style the Control however I want without it looking like a button, and I want it to still work without the user having javascript enabled.
Any suggestions?
I think the answer is none. The button submits the form (as buttons will do) but no other controls auto-submit a form without a client side event handler.
Note that this also applies to the Link button.
_doPostback is the heart of ASP.NET. If you don't want to require the use of Javascript then ASP.NET isn't the language for you.
I'm working on developing a custom control to select items from a predefined list. This is accomplished via 2 ASP.NET ListBox controls, with a few buttons to trigger the movement of ListItems from one ListBox to the other (lets call these ListBoxes lstSelected and lstDeselected).
This is easy enough to do in ASP.NET or JavaScript independently: I have both working. However, if modifications are made via JavaScript, ASP.NET retains no knowledge of this. Is there any way to register the creation of of options in a select tag without AJAX?
You could also do this with traditional postbacks, it doesn't have to be ajax. The postbacks would be triggered by clicking your buttons which change which items are in which listboxes.
You could have a couple of hidden fields, say hdnHasSelectedChanged and hdnHasDeselectedChanged, and set those fields in your javascript code. Then, when a postback really happens, your code-behind can read those hidden fields to detect if changes occurred.
I'm writing my own Modal Popup as a template control in ASP.NET. I got two template containers - one for the heading of the window and one for the actual control i want to display in the modal window (let's call it the form control). The form controls can contain server controls like buttons, textbox'es etc.
It works well, except when i want to access the form control in my web page. My codebehind won't recognize the content in the template control - just like it won't in, say a Repeater. So i figured a Panel control works just like what i need, except the Panel control only has "one container" and i'd really like to be able to set both a header and the content (form control).
I figured i could overwrite the Panel control to add my own html but that would limit my header to be something encodeable in an attribute. So is my best bet really to expose the Heading as just a property, instead of a template and thus being limited in what i can write for heading?
Just as you can with a repeater, try using the ParentControl.FindControl(...) method to get the control you desire.
I ended up overriding the Panel control, accepting that i can only "pass" one set of controls as its children. Also i had to make the heading a property i set as an attribute on the modalpopup control.
Even though i couldn't solve it the way i wanted to, i think the solution is good enough.