DNN with Telerik RadButton doesn't render Text from resource file - c#

I hope that someone can help me with issue.
In a DNN custom module that I'm creating, I have a RadButton that doesn't show the Text value from the resource file. Other controls do read the values from the resource file.
I tried from the ascx and from the code behind. Another strange thing is that when debugging the application from the code behind I see the Text attribute.
the control definition is:
<dnn:dnnRadButton ID="CntUsSubmit" runat="server" OnClick="ProcessSendMail" resourcekey="CntUsSend"
SingleClick="true" SingleClickText="Submitting..." Style="clear: both; float: left; margin: 10px 0;" ></dnn:dnnRadButton>
inse Page_Load I make the localization (too):
CntUsSubmit.Text = Localization.GetString( "CntUsSend.Text", LocalResourceFile );
the page is rendered as:
<span id="dnn_ctr474_View_CntUsSubmit" class="RadButton RadButton_Default rbSkinnedButton"
style="clear: both; float: left; margin: 10px 0;">
<input class="rbDecorated" type="button" name="dnn$ctr474$View$CntUsSubmit_input"
id="dnn_ctr474_View_CntUsSubmit_input" value="" />
<input id="dnn_ctr474_View_CntUsSubmit_ClientState"
name="dnn_ctr474_View_CntUsSubmit_ClientState" type="hidden" />
</span>
the Sys.Application.add_init function shows:
Sys.Application.add_init(function() {
$create(Telerik.Web.UI.RadButton, {"_accessKey":"","_postBackReference":"WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions('dnn$ctr474$View$CntUsSubmit', '', true, '', '', false, true))","clientStateFieldID":"dnn_ctr474_View_CntUsSubmit_ClientState","iconData":{},"imageData":{},"singleClick":true,"singleClickText":"שולח...","toggleStatesData":[],"uniqueGroupName":"","uniqueID":"dnn$ctr474$View$CntUsSubmit","value":"שלח"}, null, null, $get("dnn_ctr474_View_CntUsSubmit"));
});
I understand the control knows the Text from the add_init, but the rendered button doesn't get the it. Can someone help me how to solve this?
I'm using DNN 7.0.2, VS 2012, for Framework 4.0

That's odd. You could try the following in its OnClientLoad event:
function OnClientLoad(sender, args)
{
sender.set_text(sender.get_text());
}
Try alerting the get_text() first to see if it retursn what you need. If so, you can put this in a global JS file and add the event handler through a Theme.
If this doesn't help try putting the desired text in a hidden field (e.g. with a unique class) and again use the set_text() method.

In the end I gave up with RadButton, instad I used Encosia's Postback Ritalin which made the trick nice and smoothly.

Related

onserverclick not firing for input of type date

I am building a web application in ASP.NET using webforms.
I have an input html element which I have set to run at server and I want to fire an event whenever the date is changed.
<input id="datePicker" class="form-control" style="display: inline; margin-left: 5px; width: 15%; text-align: center;" type="date" runat="server" onserverclick="Date_Changed"/>
I have the event in my codebehind:
protected void Date_Changed(object sender, EventArgs e) {}
However, the event is never fired.
Don't believe that server side click events can be wired up to a input that way (using the onserverclick).
I would consider dropping in a HTML button, say like this:
<button id="datePicker"
class="form-control"
style="display: inline; margin-left: 5px; width: 15%; text-align: center;"
type="date"
runat="server" onserverclick="Date_Changed" />
And even better yet, drop in a asp.net button.
If you drop in a input tag, then I don't think you can get the asp.net system to wire this up for you. You could I suppose write this:
(this is what a plane jane above button becomes:
<input onclick="__doPostBack('Button11','')"
name="Button11" type="button" id="Button11" value="button">
So you could try above - but using a "input" tag I don't believe will work, but try a HTML button as per above - that does allow "on server click".
Do keep in mind that if you drop in a asp.net text box, and set textmode = "date"?
Say like this:
<asp:TextBox ID="MyDateTest" runat="server" TextMode="date">
</asp:TextBox>
Then you see this:
So, above is a built in feature - you don't need any js, bootstrap, or anything at all.
but, you could add a "client" side click to your markup, as I posted a above the do post-back would (should) run your click event. However, it probably a whole lot better to not fight asp.net, since then you quite much hand coding a lot of HTML, and doing that means you quite much toss out most of the features of why you would use asp.net in the the first place (that means to take advantage of all the built in controls, and the pre-processing of those controls for you).

C# Selenium wait until element display is equal to none - works only on debug

I'm facing some trouble while automating a form that contains a div with style="display: none;"
It has an Id, but I can't use it without the debug.
The issue is: there is a dropdown that loads its options only after this "load image" goes away.
So I tried many solutions and every single option from the SeleniumExtras.WaitHelpers ('cause the old is going to be deprecated in C#).
The closer I get from a solution was this code here:
https://stackoverflow.com/a/58100882/11670912
Here is my code:
<div id="updateProgress" style="display: none;" role="status" aria-hidden="true" xpath="1">
<div id="divLoading" style="position: absolute; z-index: 10; left: 450px; top: 90px;">
<img id="ajaxLoadNotificationImage" src="../images/ajax-loader-center.gif" alt="[image]">
</div>
</div>
--
WebDriverWait wait = new WebDriverWait(WebDriver, TimeSpan.FromSeconds(90));
wait.Until(WebDriver =>
{
return WebDriver.FindElement(By.Id("updateProgress")).GetAttribute("style").Contains("display: none;");
});
I've tried these as well:
wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeSelected(By.XPath(profilePage.LoadingStateImg.GetAttribute("style").Contains("display: none;").ToString())));
wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.InvisibilityOfElementLocated(By.XPath(profilePage.LoadingStateImg.GetAttribute("style").Contains("display: none;").ToString())));
Not listed above, but I've tried:
- InvisibilityOfElementWithText
- StalenessOf
- ElementIsVisible
- TextToBePresentInElementValue
It seems doesn't even get into these lines of code while running.
The debug shows the text ok with the attribute "display: none;" and goes to the selection of the required dropdown.
I don't want to use Thread.Sleep(), but so far it is the only thing that works.
*(Tread.Sleep works, but obviously I'm not trying to get into it, because the page is so slow that I'd need to 40-60 seconds...)
Thanks in advance!
I've solved it by myself.
It was needed to check at first if the element was visible (By locator), so I could check then if it was not visible. The element probably blinks at page before being shown definitely on page:
WebDriver.WaitForElementIsVisible(By.Id(profilePage.LoadingStateLocator));
WebDriver.WaitForElementIsNotVisible(profilePage.LoadingStateImg);

asp:Literal strips out title attribute value

I am working on a asp.net website (web forms and mvc) where asp:Literal is used in a few pages.
I needed to change the content of one page to add a simple title attribute to the existing tag.
So i need the rendered result to be:
<a href="test.jpg"
title="title here"
id="testimage"
rel="hint-text: CLICK TO ZOOM"
style="position: relative; display: inline-block">image goes here</a>
But after rendering, it looks like that:
<a href="test.jpg"
title id="testimage"
rel="hint-text: CLICK TO ZOOM"
style="position: relative; display: inline-block">image goes here</a>
At first i thought it could be something to do with the controls Mode property, but even if i change the Mode to PassThrough it still does not render the value of the tittle attribute.
EDIT: The code for the literal is as folows:
LiteralControl.Text = "<a href='test.jpg' title='title here' id='testimage' rel='hint-text: CLICK TO ZOOM' style='position: relative; display: inline-block'>image goes here</a>"
Does any of you guys have this problem and happens to know the solution?

How to disable the whole page under some condition in the code behind?

I have a specific page ,i want in the button click event and under some condition to disable all the controls and grayout the whole page ,showing an information message to state that the confirmation is done .
How to do that in a general way ?
You basically want a mask. Although not exactly to your question look at this jQuery based load mask plugin, you should be able to adapt it to suit your needs:
https://code.google.com/p/jquery-loadmask/
Have a look at the modal popup that is included in the Ajax Control Toolkit:
http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/ModalPopup/ModalPopup.aspx
This will allow popup of a message that effectively prevents interaction with the rest of the page.
$(document).ready(function() {
if(Conditions satisfy){
$('#div_controls').attr('disabled', true);
$('#div_status').attr('disabled', false);}
else{ $('#div_controls').attr('disabled', false);
$('#div_status').attr('disabled', True)
}
});
In HTML
<div id="div_status"> Your Message with your styles </div>
<div id="div_controls"> Your Controls inside this Div </div>
Without any Post back,WO loosing the data, State It can be done..
or Check this demo
http://www.zurb.com/playground/reveal-modal-plugin
you can make all controls "invisble" after user click by
foreach (Control c in Page.Controls)
c.Visible = false;
Or a better way would be to use plugins such as Modal-UpdateProgress
in HTML
<div id="layer"></div>
<div id="container">
----
----
----
</div>
and in CSS
#layer{
background: none repeat scroll 0 0 white;
height: 100%;
left: 0;
position: fixed;
top: 0;
width: 100%;
z-index: 100000;
}
This will disable the page ( or it will act like disabled ).

Pass values to javascript in ASP.NET

I have an ASP textbox control where I need to execute some javascript function when the OnClick event occurs. I need to pass to that javascript function two IDs of other controls on that page. My textbox markup is as follows:
<asp:TextBox ID="txtMonthDisplay" runat="server" Style="border-top: none; border-left: none;
border-right: none; border-bottom: solid 1px blue; cursor: pointer; color: Blue;
width: 35px;" EnableViewState="True" MaxLength="3" onClick="javascript: ShowBox('<%= divYear.ClientID%>', '<%= txtYearDisplay.ClientID %>');"></asp:TextBox>
But whenever it calls the javascript function I have setup an alert to check the incoming values, and they are simply <%= txtYearDisplay.ClientID %> and <%= divYear.ClientID%>. Not the actual IDs of those controls.
What am I missing here, or doing incorrectly? I'm not well versed with asp.net so server vs. client side is a bit fuzzy for me.
Thanks
You can't Response.Write (<%= %> is shorthand for Response.Write) into a server tag (usually).
Instead, you can write your onclick handler in the codebehind:
txtMonthDisplay.Attributes["onclick"] = string.Format(
"ShowBox('{0}', '{1}');",
divYear.ClientID,
txtYearDisplay.ClientID);
By the way, you don't need the javascript: prefix. That is only necessary when setting the href of a link to execute script. It is not needed for event handlers such as onclick.
Then pass the variables from codebehind:
protected void Page_Load(object sender, EventArgs e){
txtMonthDisplay.Attributes.Add("onClick",
String.Format("ShowBox('{0}','{1}')",
divYear.ClientID,
txtYearDisplay.ClientID));
}
The <%= ... %> displaying expression is an equivalent of the embedded code block that contains only the Response.Write(…) statement. This is the simplest way to display information such as a single string, an int variable, or a constant.
Remember that the displaying expression cannot be used in the attributes of server controls. This is because the .NET Framework directly compiles the whole expression instead of the displaying content as the value to the attribute.
http://support.microsoft.com/kb/976112/en-us
Hmm, your markup looks correct, I would try a couple of things, first try adding the onclick event through code and see if the IDs get added. That way you will know if your textbox generation works correctly.
You could also work around by doing click binding after the document.ready using JQuery and having the values as hidden values on the form.

Categories