MVC :: IsAjaxRequest Is Always False?
Mar 22, 2010
i am using MVC 2 RC and VS2010
when i want to use Ajax for my application IsAjaxRequest returns false
this is my code for view
[Code]....
and this is my controller
[Code]....
also i was added these libraries to my master page
[Code]....
the Request.IsAjaxRequest returns false
View 8 Replies
Similar Messages:
Feb 11, 2011
I have been googling/SO:ing this issue for a while and many seem to be sharing this, but I haven't found any successful solution to my problem.
Using MVC3 and Razor.
Master page contains:
<script src="@Url.Content("~/Scripts/jquery-1.5.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/MicrosoftAjax.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/MicrosoftMvcAjax.js")" type="text/javascript"></script>
AjaxTest.cshtml contains:
<div id="AjaxTestDiv">content</div>
@Ajax.ActionLink("Update", "AjaxTester", new AjaxOptions { UpdateTargetId = "AjaxTestDiv" })
AjaxTester action method:
public string AjaxTester()
{
if (Request.IsAjaxRequest())
{
return DateTime.Now.ToString();
}
else
{
return "FAIL";
}
}
I always get the "FAIL" returned, to a blank page, not in the targeted div.
Edit: Also note that if I remove the if (Request.IsAjaxRequest()), I still don't get back anything to the targeted div, but instead a blank page.
Edit2: Looking at the HTML generated, this is my link:
<a data-ajax="true" data-ajax-method="POST" data-ajax-mode="replace"
data-ajax-update="#AjaxTestDiv" href="/Area/AjaxTester">Update</a>
Have tried switching the method to GET, to no avail.
View 1 Replies
Jan 11, 2010
I've an action in a controller that returns different content if the request is Ajax or not:
[Code]....
So, from the view I can fill a <div> with the PartialView (RenderPartial), calling the same action (allowing javascript disabled clients). The problem is the cache, because when the request has cached as a normal request, if later sends the request as an Ajax request, the view is rendered very bad.
The question is: Is there any way to use OutputCache to allow to cache in different entries this two types of requests (Ajax and not Ajax).
View 4 Replies
Sep 16, 2010
I've just discovered that the X-Requested-With header in IE is always "XMLHttpRequest, XMLHttpRequest" instead of just "XMLHttpRequest". I found the reason in MicrosoftMvcAjax.debug.js at line 280 (MVC 2.0). Seems there is no need to add this header again as it is already done in Microsoft AJAX Library. And because of this IsAjaxRequest extension method doesn't work anymore if there is no X-Requested-With param in the request body. And this make X-Requested-With header useless in IE.
In Firefox there is no problem as it doesn't append but replace the existing header value. Not tested in other browsers.
View 9 Replies
Mar 21, 2010
I'm using IOC containers that wrap items of HttpContext, such as Request and Session variables, to simplify mocking of it for testability.
Since IsAjaxRequest() is an extension method, it doesn't show up in HttpContext.Current.Request.
Is it possible to wrap extension methods with a IOC container? How?
View 11 Replies
May 28, 2010
I'm just starting to use the TestHelpers in MvcContrib. I want to try and test an action method on my controller that itself tests if IsAjaxRequest() is true. I've used the same code that is shown in the TestHelper samples to set up the TestControllerBuilder
_controller = new StarsController();
_builder = new TestControllerBuilder();
_builder.InitializeController(_controller);
So that _controller has all the faked/mocked HttpContext inside it, which is really great. But what do I do now to force IsAjaxRequest() on the internally faked Request object to return true?
View 2 Replies
Mar 26, 2016
I have an approve button.on clicking on this button it should show that an inactive value is present .Onclicking yes conformation it should save the data or else clicking on no conformation should return false; how i will do that?After alert it always submit the data.
protected void ibtApprove_Click(object sender, ImageClickEventArgs e)
{
string otherAffiliateName = txtRequestedAffiliate.Text;
int inActiveAffiliates = new BLRating().InActiveAAffiliateChecking(otherAffiliateName);
if (inActiveAffiliates > 0)
[code]...
This is the code i used.how i wiil stay back on Confirm 'no' click?
View 1 Replies
Jan 19, 2010
public CheckBox[] cb = null;
int z=0;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
cb = new CheckBox[count - k];
//Database code.........
while (dr.Read())//read data from access database
{
cb[z] = new CheckBox();
cb[z].Text = dr["Member_Name"].ToString();
Panel2.Controls.Add(cb[z]);
Panel2.Controls.Add(new LiteralControl("</br>"));
z = z + 1;
}
}
}
protected void Button6_Click(object sender, EventArgs e)
{
for (int x = 0; x < cb.Length; x++)//ERROR IS HERE:Object reference not set to an instance of an object.
{
if (cb[x].Checked == true)//EVERY TIME I GOT FALSE VALUE
{
//processing check boxes
}
}
}
View 1 Replies
Apr 2, 2011
Basically, when the page loads i set the div visibility to false. When i click the button, i want the code behind function to be called, and the div tag to be visible, true.
$('#Button2').click(function () {
$('#edit').show(function () {
});
});
<input type="submit" id="Button2" runat="server" value="Search" OnServerClick="Button1_Click" />
but when clicking the button, the page posts back, causing the div tag to be invisible all times.
I can set the return false to the onlclick event of the button , but i need to call the function also.
View 4 Replies
Jun 28, 2010
tell me the use of Validaterequest False?
View 4 Replies
Nov 2, 2010
I'm using FreeTextBox HTML editor in some webforms in my asp.net project . if I do not set ValidateRequest property to false I get this error :
A potentially dangerous Request.Form value was detected from the client
It's OK in admin folder though , Because only authorized users have access to work with it . But how about public pages like sections where every users have access to leave comments(using FreeTextBox for collecting users comment ) ? Isn't risky for XSS Attack ? If the answer is not Yes , So what's ValidateRequest property for?
View 3 Replies
Jan 19, 2010
public static CheckBox[] cb = null;
int z=0;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
cb = new CheckBox[count - k];
//Database code.........
while (dr.Read())//read data from access database
{
cb[z] = new CheckBox();
cb[z].Text = dr["Member_Name"].ToString();
Panel2.Controls.Add(cb[z]);
Panel2.Controls.Add(new LiteralControl("</br>"));
z = z + 1;
}
}
}
protected void Button6_Click(object sender, EventArgs e)
{
for (int x = 0; x < cb.Length; x++)//ERROR IS HERE:Object reference not set to an instance of an object.
{
if (cb[x].Checked == true)
{
//processing check boxes
}
}
}
View 3 Replies
May 4, 2010
To reduce the loading time this blog we set generatePublisherEvidence to false in the app.config for executables.
<configuration>
<runtime>
<generatePublisherEvidence enabled="false"/>
</runtime>
</configuration>
Where do I set it for web apps? The blog that this does not go to the web.config. Where else should I put it?
View 1 Replies
Aug 20, 2010
I have a code below in my gridview.
I want to set the HeaderText to Visible = false on my code behind. Can i do that?
[code]....
View 4 Replies
Nov 3, 2010
I am using a multiline textbox for publishing a note but taking the content in a div through inner HTMl.
divMessageDescription.InnerHtml = dbreader["Message"].ToString();
but now for a particular group of people I want to make the read only property of this div as false.
View 2 Replies
Apr 1, 2010
I have set enableViewState to false, why my textbox still remain my last value after i hit the postback button?
[Code]....
View 3 Replies
Feb 9, 2010
What is the syntax for an not true or false if statement in nVelocity (or Velocity)?
And more importantly, where is this in the nVelocity docs? I've been Googling for quite a while to no avail.
I've tried several different combinations such as:
#if (!$artist.IsFestival)
$artist.FestivalName
#end
and
#if ($artist.IsFestival == false)
$artist.FestivalName
#end
So frustrating!
View 1 Replies
Feb 21, 2011
I want to store certain html tags in my database to the layout of content, for example <h3> and <p> tags. The problem is with ValidateInput set to True, you get "Potential Danger error" when you try sending content with html tags.
With it set to False, you open yourself to all sorts of potential dangers. So Here is what I'm wanting to achieve:
I hope you like the image ! lol I spent 10 minutes in Photoshop to create it.
So eventhing that goes in, I want as encoded, but when I get content back, I want to decode only the <h3> and <p> tags. ! What do you think of my solution ? Bad, Good ?
View 16 Replies
Sep 29, 2010
I am working on rewriting URLs Urlrewriting.net, and have run into what seems to be a common problem but I can seem to fix it. I'll present a simplified case.
The URL rewriting is working perfectly with the rule:
<urlrewritingnet rewriteOnlyVirtualUrls="true" defaultPage="default.aspx" defaultProvider="RegEx" xmlns="http://www.urlrewriting.net/schemas/config/2006/07">
<rewrites>
<add name="catalog" virtualUrl="^~/catalog/(.*)/(.*).aspx" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="~/catalog.aspx?cid=$1&c=$2" ignoreCase="true"/>
</rewrites>
</urlrewritingnet>
On the page I have a DataList with 2 asp:buttons inside. When clicked, the page refreshes but does nothing.
I followed ScottGu's article to impliment a form control adapter to rewrite the action of the form to match the rewritten URL.
Page URL in the browser:
[URL]
<form name="aspnetForm" method="post" action="/dev/catalog/13/Music.aspx" id="aspnetForm">
I now see the correct URL on the form action, and when debugging I can see the page load event firing.
The problem now is that every time the page loads Page.IsPostback is false, causing the page to rebind the DataList and therefore ignore the ItemCommand the buttons should be triggering.
if (!Page.IsPostBack)
PopulateControls();
I'm using .NET 3.5 SP1, there is a ScriptManager on the master page but no UpdatePanel on this page. I've also tried resetting the Form.Action property and bypassing ScottGu's solution with the same result. If I go to the page URL directly without using the rewriter everything works fine.
View 3 Replies
Jan 31, 2010
etailsView is bound to ObjectDataSource. Inside Detailsview's EditItemTemplate are two TextBoxes ( T1 and T2 ). T1 is mapped to update parameter of type String, while T2 is mapped to update parameter of type DateTime. ssuming both TextBoxes contain an empty string, then when I try to update the data source by clicking on DetailsView's Update button, ODS ( or is it perhaps DetailsView ) automatically converts T1's empty string to null, while T2's empty string doesn't get converted to null. I've tried to prevent ODS from converting T1's empty string to null by setting T1's update parameter's ConvertEmptyStringToNull property to false ( I 've also set <asp:TemplateField ConvertEmptyStringToNull="false" ...>, but to no effect.a)Any idea why T1's empty string gets converted, while T2's doesn't?b) Also, how can I prevent the conversion( BTW - I realize I could convert null back to empty string inside update method )?
View 1 Replies
Feb 12, 2011
If I have a grid, and it is binded to some data, but the visible=false for the grid, will it consume any resources for initializations or for retrieving data to perform the bindings?
How about if the grid is inside a div, and the div visible=false
View 2 Replies
Jan 16, 2011
I've an EntityCollection< T > which contains an element but the Contains method returns false.
I've overriden T's 'Equals' method but the 'Contains' method does not call it (while it's said so in documentation).
When I do foreach (T x in coll), x.Equals(element) returns true.
code:
contains(object entCol, object val)
{
var coll = (ICollection<GraphicSockets>)entCol;
var socket = val as GraphicSockets;
foreach (GraphicSockets sock in coll)
socket.Equals(sock); //true for first element, GraphicSocket's Equals function called
coll.Contains(socket);//false, Equals function not called}
the code i'd actually like to use is
private static bool contains(object entCol, object val)
{
Type entColType = typeof(EntityCollection<>).MakeGenericType(val.GetType());
MethodInfo contains = entColType.GetMethod("Contains");
return (bool)contains.Invoke(entCol, new object[] { val });
}
this worked once but stopped when i started using wcf, i wonder how this contains method works.....
View 2 Replies
Jul 20, 2010
I've been tinkering with MVC2 for a bit now and am REALLY excited about how well it works! But one thing that has come up seems simple enough to resolve but was hoping someone here had a better idea than I have.My model has some boolean fields and when I write this: <%= Html.Encode(model => model.MyBooleanField) %> it spits out True or False as expected. What I'd like to do is replace that with 'Y' or 'N'Some initial ideas I've had: use a jquery script to spin though all the elements on the page and replace True/False with Y/N but this raises performance concerns.Another idea I had was to build an extension method off the Html class to accomplish this but was hoping someone might have a better/quicker solution?
View 6 Replies
May 7, 2015
I used below code in behind code and make ssl=false for smpt
SmtpClient smtp = new SmtpClient();
smtp.EnableSsl = false;
and this is for pop3
pop3Client = new Pop3Client();
and I want make ssl=false for pop3 but I can't find attribute EnableSsl for pop3Client like
smtp.EnableSsl = false;
how I can make ssl=false for pop3client?
View 1 Replies
Aug 17, 2010
I have cause validation true on button. And I am checking the Page.IsValid in c# code. But its always returning false value?
View 2 Replies