iam using calender control in asp.net 2.0
as it is using master pages.. iam opening a window form content pages..
on window.close it is giving me null object as its not getting form name
you help will be appreciated
code on content page:
<a onclick="openwindow();" ahref="#">
<img src="Images/calendar.gif" style="width: 20px; height: 20px" border=0/></a>
<input ID="Text1" runat="server" readonly="readOnly" type="text" />
function openwindow() {
window.open('/Calender.aspx', 'calendar_window','width=154,height=188');
}
code on opened window from content page
protected void Calender1_SelectionChanged(object sender, EventArgs e)
{
string strjscript = "<script language='javascript'>";
strjscript += "window.opener." + HttpContext.Current.Request.QueryString["formname"];
strjscript += ".value = '" + Calender1.SelectedDate.ToString("yyyy-MM-dd") + "'; window.close();";
strjscript += "</script" + ">";
Literal1.Text = strjscript;
}
protected void Calendar1_dayrender(object sender, DayRenderEventArgs e)
{
if(e.Day.Date==DateTime.Now)
{
e.Cell.BackColor = System.Drawing.Color.LightGray;
}
}
Looks like you are not following this tutorial but not exactly what it is doing.
Points to note:
1: Make sure you are naming your form
2: Pass textbox reference via querystring i.e. Calender.aspx?formname=frmCalendar.txtDate
3: Path to your calender.aspx is correct.
You are close to solution but may be you need to share your main page code as well for us.
Edit 1
Ok I see now what you are saying. Add this script block to your content page:
<script type="text/javascript">
function openwindow() {
var txtid = '<%=txtDate.ClientID %>';
var frmid = '<%=Page.Form.ClientID %>';
var qs = "formname=" + frmid + "." + txtid;
window.open('/Calendar.aspx?' + qs,'calendar_window', 'width=154,height=188');
}
</script>
Although if possible try using jquery datepicker and you can post your code and issue if you want to go that route.
Related
I am using asp control SlideShowExtender in a aspx page.
I am using the previous and next buttons.
I want to add a delete button. Is there a way to find out which picture the user is currently on? I'm having a hard time finding how to get the name of the image SlideShowExtender is currently showing.
Thanks for the help =)
$find("<%= slideshowextend1.ClientID %>")._currentValue.ImagePath;
$find("<%= slideshowextend1.ClientID %>")._currentValue.Name;
Crazy workaround
Add MouseDown event to image (OnClick would not work)
asp:Image runat="server" ID="MainImage" Width="1000" ImageUrl="" onmousedown="javascript:return MainClick();"
JavaScript
function MainClick() {
i = document.getElementById('<%=MainImage.ClientID %>');
c = document.getElementById('<%=MainImageClick.ClientID %>');
c.value = i.getAttribute("src");
__doPostBack(null, null);
return true;
}
</script>
C# - there is probably some way of setting the sender but I am working on a over budget project
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
string mainImageClick = MainImageClick.Value;
if (!string.IsNullOrEmpty(mainImageClick))
DoMainImageClick(mainImageClick);
MainImageClick.Value = string.Empty;
}
}
I have seen a couple of other posts on here regarding the use of Recaptcha with ASP.net UpdatePanels but have not yet found an answer that solves my problem.
Here is my ASPX code :
<asp:UpdatePanel ID="updRecaptcha" runat="server" UpdateMode="Always">
<ContentTemplate>
<recaptcha:RecaptchaControl ID="btnrecaptcha" runat="server" Theme="clean" PrivateKey"<%$ Resources: General, CaptchaPrivateKey %>" PublicKey="<%$ Resources: General, CaptchaPublicKey %>" />
<asp:Label ID="recaptchaerror" runat="server" style="color: Red;"/>
</ContentTemplate>
</asp:UpdatePanel>
So the Recaptcha control lives within a user control that uses several .Net validation controls (e.g. RequiredFieldValidator). I need to valdiate the Recaptcha and the ASP.net controls before allowing the process to continue.
If any of the validation fails (Recaptcha or .Net) then the Recaptcha control disappears. Looking at the HTML source, the control isn't loading at all after the Postback - eventhough I am telling the UpdatePanel to update.
I can't reload the page completely as this all appears as an overlay on top of the page and there are other form fields on the page behind.
Please help!
Edit:
From C# when the Recaptcha fails I am calling this code :
ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "InvalidRecaptcha", "alert('Recaptcha Failed');Recaptcha.reload();alert('Recaptcha Reloaded');", true);
Both of the alert statements fire but the Recaptcha still does not load.
The accepted solution did not work for me. Here is the answer that I have tried and is working:
ASP.Net, disappearing Recaptcha, UpdatePanels and Partial PostBacks: Fixed once and for all
Basically it involves creating a hidden div and using jquery to re-render the html. Also the blog post gives a nice little breakdown of the typical solutions (e.g., using RegisterClientScriptBlock with a simple reload) and why they fail.
<div runat="server" id="pbTarget" visible="false"></div>
<recaptcha:RecaptchaControl ID="recaptcha" runat="server" Theme="clean" />
code behind:
protected void btnSubmit_Click(object sender, EventArgs e)
{
recaptcha.Validate();
if (!Page.IsValid || !recaptcha.IsValid)
{
pbTarget.Visible = true;
ScriptManager.RegisterClientScriptBlock(
recaptcha,
recaptcha.GetType(),
"recaptcha",
"Recaptcha._init_options(RecaptchaOptions);"
+ "if ( RecaptchaOptions && \"custom\" == RecaptchaOptions.theme )"
+ "{"
+ " if ( RecaptchaOptions.custom_theme_widget )"
+ " {"
+ " Recaptcha.widget = Recaptcha.$(RecaptchaOptions.custom_theme_widget);"
+ " Recaptcha.challenge_callback();"
+ " }"
+ "} else {"
+ " if ( Recaptcha.widget == null || !document.getElementById(\"recaptcha_widget_div\") )"
+ " {"
+ " jQuery(\"#" + pbTarget.ClientID + "\").html('<div id=\"recaptcha_widget_div\" style=\"display:none\"></div>');"
+ " Recaptcha.widget = Recaptcha.$(\"recaptcha_widget_div\");"
+ " }"
+ " Recaptcha.reload();"
+ " Recaptcha.challenge_callback();"
+ "}",
true
);
return;
}
else
{
//normal page processing here...
If you are using Recaptcha 2.0 this is your Javascript
<script type="text/javascript">
function CaptchaReload() {
Recaptcha.create("yourpublicKey", 'yourRecaptchadiv', {
theme: 'white',
callback: grecaptcha.reset()
});
}
This is your recaptcha Div
<div class="g-recaptcha" data-sitekey="yourPublicKey"></div>
Then at end of postback event call the Javascript
protected void txtEmail_TextChanged(object sender, EventArgs e)
{
if (txtEmail.Text != string.Empty)
{
ValidateEmail();
ScriptManager.RegisterStartupScript(this, this.GetType(), "CaptchaReload", "$.getScript(\"https://www.google.com/recaptcha/api.js\", function () {});", true);
}
}
Forget the ScriptManager. All you need is this script in the page. Change accordingly for your identifiers:
<script type="text/javascript">
// RECAPTURE CODE FOR RELOADING AFTER INCORRECT ENTRY
if (typeof Sys != 'undefined') {
var requestManager = Sys.WebForms.PageRequestManager.getInstance();
requestManager.add_endRequest(function(sender, args) {
$('<div id="recaptcha_widget_div"/>').appendTo('#recaptcha_widget_div2');
if (typeof Recaptcha != 'undefined') {
Recaptcha.create(recaptcha_key, "recaptcha_widget_div",
{
theme: "red",
callback: Recaptcha.focus_response_field
});
}
});
}
Surprisingly, I didn't need to apply the RegisterClientScriptBlock call to make it work.
I just use:
UpdateMode="Always"
for the updatepanel and on the server side I call:
updatePanel.Update();
This also prevents the captcha from displaying a new challenge.
My answer is basically the same as "User" (that worked !), but to help anyone using VB.
I would have commented there, but I have zippo rep...
(hope this isn't too much of an infraction, and that it helps someone out)
I ported the meat of this to VB.NET:
pbTarget.Visible = True
Dim _sb As New StringBuilder
With _sb
.Append("Recaptcha._init_options(RecaptchaOptions);")
.Append("if ( RecaptchaOptions && ""custom"" == RecaptchaOptions.theme )")
.Append("{")
.Append(" if ( RecaptchaOptions.custom_theme_widget )")
.Append(" {")
.Append(" Recaptcha.widget = Recaptcha.$(RecaptchaOptions.custom_theme_widget);")
.Append(" Recaptcha.challenge_callback();")
.Append(" }")
.Append("} else {")
.Append(" if ( Recaptcha.widget == null || !document.getElementById(""recaptcha_widget_div"") )")
.Append(" {")
.Append(" jQuery(""#")
.Append(pbTarget.ClientID)
.Append(""").html('<div id=""recaptcha_widget_div"" style=""display:none""></div>');")
.Append(" Recaptcha.widget = Recaptcha.$(""recaptcha_widget_div"");")
.Append(" }")
.Append(" Recaptcha.reload();")
.Append(" Recaptcha.challenge_callback();")
.Append("}")
End With
ScriptManager.RegisterClientScriptBlock(recaptcha, recaptcha.[GetType](), "recaptcha", _sb.ToString, True)
I was able to make it work using version 2.1.0.0 of the reCAPTCHA library for .NET with webforms, script manager and inside an update panel.
First, in the .aspx page outside of the update panel I'm loading the Google reCAPTCHA library:
<script src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit"
async defer></script>
Second, in the .aspx page inside the update panel I added a div that will work as the target panel to load the reCAPTCHA:
<div runat="server" id="pbTarget" visible="false"></div>
<cc1:Recaptcha ID="recaptcha" runat="server" Theme="Clean" />
Third, in the code behind at the end of my postback event I registered a startup script to render the reCAPTCHA in my target panel
Private Sub cmdSubmit_Click(sender As Object, e As EventArgs) Handles cmdSubmit.Click
pbTarget.Visible = True
ScriptManager.RegisterStartupScript(
UpdatePanel1,
UpdatePanel1.GetType(),
"loadCaptcha",
"grecaptcha.render('" & pbTarget.ClientID & "', {'sitekey': 'YourKey' });",
End Sub
You need to reload reCaptcha control with javascript, try this:
protected void Button1_Click(object sender, EventArgs e)
{
btnrecaptcha.Validate();
if(IsValid && updRecaptcha.IsValid}
{
//Some logic here
}
ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "CaptchaReload", "Recaptcha.reload();", true);
}
I am attempting to create a calendar which is just a simple UI to display dates and dates to users of our system. I have overridden the Calendar's "DayRender" event to gain access to each cell and then insert a couple of dynamic controls to display specific data. The display of the controls works great. However, I recently wanted to add a LinkButton with command arguments and capture the event to run some other logic and change the UI. I have gotten the LinkButton to display properly and it renders as a simple "" tag with the ID that is assigned. However clicking on the link does nothing and it appears that the normal "href='...javascript action...'" portion of the link is not being generated. I have a feeling this is all due to the fact that I am adding the control at the Day Render stage in the page life cycle. But if that was the case the control probably would not show up at all.
Any ideas as to why the click action is not being added yet the text and everything else are? Code is below.
Thanks for your time
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
if (Schedule != null)
{
var dayReq = from day in Schedule
where day.RequiredDate == e.Day.Date
where day.RequiredQty != 0
select day;
if (dayReq.FirstOrDefault() != null)
{
//Open the Date
e.Cell.Controls.Add(new LiteralControl("<br /><div class=\"auth-sched-req\">Req Qty: <strong>" + String.Format("{0:#,#.###}", dayReq.FirstOrDefault().RequiredQty) + "</strong><br />Prom Date: "));
//Create a link button for the promise date
LinkButton lb = new LinkButton();
lb.ID = dayReq.FirstOrDefault().ItemId.ToString();
lb.Text = dayReq.FirstOrDefault().RequiredDate.ToShortDateString();
lb.CommandName = "ShowPromise";
lb.CommandArgument = dayReq.FirstOrDefault().ItemId.ToString();
lb.Command +=new CommandEventHandler(lb_Command);
e.Cell.Controls.Add(lb);
//Close the Date
e.Cell.Controls.Add(new LiteralControl("</div>"));
}
}
}
protected void lb_Command(Object sender, CommandEventArgs e)
{
//Do some magic here
Response.Write(e.CommandArgument.ToString());
}
try this
<script type="text/javascript">
function calendarClick(day) {
document.getElementById('<%= hfValue.ClientID %>').value = day;
document.getElementById('<%= ghostButton.ClientID %>').click();
}
</script>
<asp:Button ID="ghostButton" runat="server" Style="display: none" OnClick="ghostButton_Click" />
<asp:HiddenField ID="hfValue" runat="server" />
code behind:
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
// ...
e.Cell.Attributes["onclick"] = string.Format("calendarClick({0})", dayReq.FirstOrDefault().ItemId.ToString());
// ...
}
protected void ghostButton_Click(object sender, EventArgs e1)
{
string value = hfValue.Value;
// ...
}
Check if AutoEventWireup is set to true i.e.
AutoEventWireup="true"
I ended up going another route with this request. None of the proposed solutions worked and I never could get it to work. One option we looked at was creating a custom table to build the control. We ended up changing where the information was changed and just used the calendar control as the display mechanism.
Sorry for the delay!
I have the following ASP.NET code:
<div id="panelIssue" runat="server" style="width: 450px; height: 320px;">
<gsl:IssueUC ID="ucIssue" runat="server"
OnItemSaved="ucIssue_ItemSaved"
OnItemCancelled="ucIssue_ItemCancelled" />
</div>
and then have an asp:Button on the page that simply call some methods and set some properties of the custom user control like
protected void btnNewIssue_Click(object sender, EventArgs e) {
ucIssue.ChangePanelMode(PanelModeEnum.Add);
ucIssue.FirmID = Convert.ToInt32(Page.Session["FirmID"]);
ucIssue.loadObject();
}
I know that I can use the div to show a jquery modal dialog but the question is how to set the usercontrol properties and call their methods?
I can evaluate also a different approach (e.g. changing the usercontrol).
Thanks in advance
Lorenzo
What I can suggest is that in the click event, after setting the control properties, you can emit a piece of javascript that will create and display a modal when the page finishes loading upon reaching the client.
Try something along the lines of the following snippet (not tested, may need small tweaking to work, but I hope you get the big idea):
protected void btnNewIssue_Click(object sender, EventArgs e) {
ucIssue.ChangePanelMode(PanelModeEnum.Add);
ucIssue.FirmID = Convert.ToInt32(Page.Session["FirmID"]);
ucIssue.loadObject();
//emit client script that will create and show the modal dialog
ClientScriptManager clientScriptManager = Page.ClientScript;
string scriptText = "$(document).ready(\n" +
"function() {\n" +
"$('#panelIssue').dialog({\n" +
"autoOpen: false,\n" +
"modal: true,\n" +
"width: 450,\n" +
"height: 320,\n" +
"title: \"Some title\",\n" +
"resizable: false,\n" +
"draggable: false });\n" +
"$('#panelIssue').dialog('open');\n" +
"});";
clientScriptManager.RegisterClientScriptBlock(this.GetType(), "MyScript", scriptText, true);
}
You should also look at the capabilities of the dialog creation in jQuery to see what other settings will fit your scenario better. I just used a few of the params that I have in an example of mine.
I am writing a javascript in asp.net server side (with in a button click event), this script is called if the user id and password matches and it supposed to close current window and open welcome page, but it is not happening. Below is my code, can anyone help me figure out what is the problem?
protected void okbtn_Click(object sender, EventArgs e)
{
account.txtuser = txtuid.Text;
account.txtpwd = txtupwd.Text;
account.login();
if (account.data == true)
{
string script = "<script language='javascript' type='text/javascript'>function f11(){window.close();var strLocation ;var strProfileID ;if (top.opener == null){strLocation = 'YourAccount.aspx';window.location = strLocation;}else{strLocation = 'http://' + top.opener.location.hostname+':'+ window.location.port + '/SendMail/' + 'YourAccount.aspx';top.opener.location = strLocation;top.opener.focus();}}</script>";
ClientScript.RegisterStartupScript(GetType(),"abc", script, true);
}
else
{
Label1.Text = "Invalid user name or password";
}
}
Add a OnClientClick event instead. For example:
<asp:Button id="okbtn" runat="server" text="OK" OnClientClick="window.close();" />
As for registering the startup script, you'd probably want to do this on Page_Load.
ClientScript.RegisterStartupScript(GetType(), "abc", script, true);
if you pass true argument at the end of the function parameters you don't need to add tags in your javascript codes because true means " tags will automatically wrap your javascript code"
Try in this way. If it doesn't help, please let us know.
Don't include <script></script> tag.
string script = "setTimeout(f11,10); function f11(){ window.close();}";
ClientScript.RegisterStartupScript(GetType(), "abc", script, true);