Telerik RadWindowManager - asp.net

I use Telerik radWindowManager to display alert windows.
I have code like this:
<telerik:RadWindowManager ID="window1" runat="server" ReloadOnShow="true"
EnableEmbeddedBaseStylesheet="false" EnableEmbeddedSkins="false" OnClientClose="javascript:alert('test')">
...
</telerik:RadWindowManager>
The problem is when I use this code without "OnClientClose" it works fine but when I add "OnClientClose" the alert is not displayed.
Thanks.

The OnClientClose attribute takes pointer to a JS method, not a call.
Which is why Nima M's solution works
From the Telerik website, RadControls for ASP.NET AJAX > Documentation > Client-Side Events:
The RadWindow control has a number of properties whose value is the name of a javascript function that executes when specific client-side events occur.
That is, not inline JavaScript. The equivalent properties on the RadWindowManager class work the same way.

You can probably write a separate method to handle OnClientClose:
<telerik:RadWindowManager ID="window1" runat="server" ReloadOnShow="true"
EnableEmbeddedBaseStylesheet="false" EnableEmbeddedSkins="false" OnClientClose="OnClientCloseHandler">
...
</telerik:RadWindowManager>
<telerik:RadCodeBlock ID="rcbModal" runat="server">
<script language="javascript" type="text/javascript">
function OnClientCloseHandler(radWindow) {
//Do Domething Here
}
</script>
</telerik:RadCodeBlock>

Related

clientidmode static is not working with updatepanel which forces full postback

I have RadioButtonList & Listvie in my page. I am using update panel to avoid postback Now my radioButtonList works as filter for listview. My Problem is in my radiobuttonList I have to use clientIDmode=static but if I do that then my updatepanel has no use since there is full postback when radiobuttonList gets changed. How to solve this problem without removing clientIdmode=static. I seen some solution for kind of same post but really didn't understand. Please help me.
My code has following structure.
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:RadioButtonList ID="areasList" CssClass="mark" AutoPostBack="true" runat="server" ClientIDMode="static" RepeatLayout="Flow">
</asp:RadioButtonList>
ListviewHere
</ContentTemplate>
</asp:UpdatePanel>
There is an issue with your script.
You script is not being called after postback.
So use as below,
<script type="text/javascript">
// below will execute after ajax postback
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
function EndRequestHandler(sender, args) {
//script
}
// executes after page load first time
//script
</script>
You can set the ClientIDMode of the RadioButtonList to AutoID (or not specify the attribute in the markup if that is the default value) and use a binding expression in client code to get the actual ID of the control:
$("#<%= areasList.ClientID %>")
or
document.getElementById('<%= areasList.ClientID %>')

Obout Combobox events only fire on page load

I have the following obout control on my page:
<cc1:ComboBox ID="ActivityTypeComboBox" runat="server" Width="100" AllowEdit="False">
<ClientSideEvents OnSelectedIndexChanged="alert('x')" OnItemClick="alert('y')" />
</cc1:ComboBox>
Both of the ClientSideEvents fire when the page first loads but not after that when I actually do the events.
Any idea why or what I am missing or doing wrong?
Thanks!
Don't know about "Obout" controls, but at least for Infragistics ones the ClientSideEvents only contain the function names, not actual JavaScript code.
If I'm correct, you'd have to do something like this:
<cc1:ComboBox ID="ActivityTypeComboBox" runat="server" Width="100" AllowEdit="False">
<ClientSideEvents OnSelectedIndexChanged="onActivityTypeChanged" OnItemClick="onActivityTypeClicked" />
</cc1:ComboBox>
Then in JS:
function onActivityTypeChanged()
{
//...
}
function onActivityTypeClicked()
{
//...
}
The JS functions might also get some additional parameters from the control, but you'd have to consult the documentation for that.

ASP.NET Ajax Find Component Problem

I've got a page where I have a ModalPopUpExtender which I want to show from code.
This is my site structure which is a web form within a nested masterpage:
...
<asp:Content ID="con" ContentPlaceHolderID="mainContent" runat="server">
<asp:MultiView ID="tabMultiView" runat="server">
<asp:View ID="generalTab" runat="server">
<asp:ScriptManager ID="scriptManager" runat="server">
</asp:ScriptManager>
<ajaxToolkit:ModalPopupExtender ID="newAddressModalPopup" CancelControlID="newAddressDialogCancelButton"
BackgroundCssClass="modalBackground" TargetControlID="newAddressLink" PopupControlID="newAddressDialogDiv"
runat="server">
</ajaxToolkit:ModalPopupExtender>
...
open dialog
<script type="text/javascript">
function openNewAddressDialog() {
$find('<%= newAddressModalPopup.ClientID %>').show();
}
</script>
...
The find method always returns null. I also tried findComponent, etc. It's always null. When I debugged the method I noticed that the components collection (which is kind of a dictionary with the control ID as key) is empty.
What could the problem be? BTW, I am using jQuery stuff on the page as well.
Thanks a lot!
Ok I found it. The TargetControl was not rendered in HTML because it was in another view.
In your JavaScript function try using document.getElementById("ctl00_ContentPlaceHolder1_newAddressModalPopup"). Maybe it works. Let me know if you get issues.
Or try Setting BehaviorID="someid" to the modal popupextender and use this JavaScript code:
function changeValue()
{
var myBehavior = $find("myBehavior1");
myBehavior.show();
}
Or:
var modalDialog = $find("newAddressModalPopup");
// Get reference to modal popup using the Ajax API $find() function.
if (modalDialog != null) {
modalDialog.show();
}

how to clear an label value in javascript

I have an label "test" comimg from .cs [c# code] text="data saved successfully" . but once I click the save button i need to clear its text
right now I have 3 required field validators. with message [cannot be blank, cannot be blank,cannot be blank,] as user as clicked the save button I need to clear the text of the label. But need to show the required fields validator message
any idea how to solve it
thank you
make a javascript function like:
<Script type="text/javascript">
function clearText(cntId) {
var cnt = document.getElementById(cntId);
cnt.value ="";
return false;
}
</script>
then on your submit button attach a client side event
<asp:Button id='btnSubmit' Text='Submit' onClientClick='clearText("<%this.lblLable.ClientId%>");' .... />
On the client-side use a script like this
<script type="text/javascript">
function clearLabelValue(){
var labelObj = document.getElementById("<%= myLabel.ClientID %>");
labelObj.value = "";
}
</script>
<asp:Label id="myLabel" runat="server" Text="Some text"/>
<asp:Button id="myButton" runat="server" Text="Submit" OnClientClick="clearLabelValue();return false;"/>
Didn't test it in detail, but should work.
It is not really clear what you want to achieve, although I have the feeling there may be a "better" (more standard compliant) way of achieving what you want. Maybe you could describe more clearly what you want, so we may be able to help you.
In these situations when a particular button has validation attached to it and also we need to fire some javascript what is done is to define a javascript function which is called on click of save button.
What this javascript function does:
This function will take your label and will set its value as blank so that the text is cleared.
Now in order to validate the page which happens internally (in case the javascript function is not written on the save button click) we need to explicitly call what asp.net call for client side validation.
There is a function page_ClientValidate which needs to be called from this javascript function so that validation is still done and we also do some other processing like clearing the label in this case.
<!--for cleaning to label ; -->
document.getElementById("MyLabel").innerHTML = "";
<!--and label is like;-->
<asp:Label ID="MyLabel" runat="server" ></asp:Label>
You can simply achieve this using below script:
<script type="text/javascript">
function clearLabelValue(){
document.getElementById("<%= myLabel.ClientID %>").innerText=""
}
</script>
<asp:Label ID="myLabel" runat="server" ></asp:Label>
<asp:Button id="myButton" runat="server" Text="Submit" OnClientClick="clearLabelValue();"/>

jQuery Click event on asp:button

I have a server side button as
<asp:Button ID="btnSummary" runat="server" OnClick="btnSummary_Click" Text="Next" />
I want to attach the jQuery Click event using its ID and NOT using the alternative class attribute way.
I tried to attach the click event as:
$("#btnSummary").click(function()
{
alert("1");
});
But, its click event is not fired. Also, I have also tried $("id[$btnSummary]").
Is there any way to attach the click event on asp:button using jQuery without the class attribute on the button?
Some of the options you have can be found here
How to stop ASP.NET from changing ids in order to use jQuery
EDIT:
After reading your comments on other answers, it sounds like you need to bind the onclick event handler inside of ASP.NET AJAX's pageLoad, so that it is bound on every postback, including asynchronous postbacks. On the other hand, $(document).ready() binds only once on initial page load
function pageLoad(sender, args)
{
$("#<%=btnSummary.ClientID %>").click(function()
{
alert("1");
});
}
Dave Ward wrote a nice article on the difference between pageLoad and $(document).ready().
Add ClientIDMode="Static" to your asp:button, something like this:
<asp:Button ID="Button1" runat="server" ClientIDMode="Static" Text="Button" />
This will make the ID remain the same. It disables the autogenerated names for this control.
Here is the reference for this: http://msdn.microsoft.com/en-us/library/system.web.ui.control.clientid.aspx
Check if the id attribute is in the html source when you run the site.
Do you have the click function inside a document ready function ?
-
$(document).ready(function() {
// put all your jQuery goodness in here.
});
EDIT:
Since its a server side control and the ID changes, you will need to dynamically update the javascript on every page load with the variable.
ASP.NET generates a UniqueID for client-side stuff, you can use that to bind the event. That ID is generated based on the position of that Control inside a ControlCollection and different INamingContainers, it's ugly and you can't guess it...
Add this kind of code somewhere on your page to hook up that button.
<script type="text/javascript">
$(function() { $("#<%=btnSummary.ClientID%>") }).click(function(){/*...*/});
</script>
I'm little confused here now.
Let me explain:
1. I added a button on the page:
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Button" />
<div>
2. Then I added a JavaScript and jQuery:
<script type="text/javascript">
$(document).ready(function() {
$("#Button1").click(function() {
alert("Hello world!");
});
});
</script>
3. The generated html is this:
<div>
<input type="submit" name="Button1" value="Button" id="Button1" />
<div>
Now, I don't see ASP.NET (asp.net 3.5) changing the ids. Why do I see
different behavior?
Btw. This does work when I hit the button!
Thanks.
Assigning the selector to the class worked for me.
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="My Button" CssClass="myButton"/>
<script>
jQuery(".myButton").click(function () {
alert("clicked");
});
</script>
Please use the following syntax : $("[id*=Button1]") to reference any asp control
use pageLoad when using updatepanels because document.ready only runs once on initialization of the page and loses its binding on partial postbacks.
PageLoad gets run everytime so will rebind every partial postback.
I had the same problem, this works for me
<asp:Button ID="Button1" runat="server" Text="ASP Button" OnClientClick="return false;" />
Its the addition of return false that seems to make the difference. Hope this helps.
regards
Peter
ASP.NET adds to you id (example: id "selectButton" becomes
"ctl00_middleContent_gvPeople_ctl04_selectButton");
Use the jquery syntax to search for the part of the id that doesn't change.
$("[id='_selectButton']")
Please try below:
document.getElementById("<%=button1.ClientID %>").click();
Wrap this <asp:Button/> inside a html <div> container.
<div id="testG">
<asp:Button ID="btn1" runat="server" Text="TestButton" />
</div>
$(document).ready(function () {
$("#testG").click(function () {
alert("1");
//your code
});
});
You have reached there. There are two ways i guess,
Either inspect the control from Browser and See the Control ID, looks like ct1000_ btnSummary. use this ID on Click event of jQuery.
replace code
$("#ctl00_contentplcedholder_btnSummary").click(function()
{
alert("1");
});
Next one is quite easy just add an attribute ClientIdMode="static" to your control and use your actual Jquery click event it will fire.

Resources