I've created my website that used to show the products; when the user click on the product, it will show the product detail of each item: I want to put the Facebook Like Button inside them.
I tried using http://developers.facebook.com/docs/reference/plugins/like/. This is the url that I tried to put: http://ff/Products/ProductSpec/ (it is in my local), but actually each product have different parameter string due to its ID.
<iframe src="http://www.facebook.com/plugins/like.php?
href=http://www.example.com/Prod/Spec/1115?dep=82&cat=243&tab=2"
scrolling="no" frameborder="0"
style="border:none; width:450px; height:80px"></iframe>
But the URL that shared on my wall in facebook just only "http://www.example.com/Prod/Spec/1115?dep=82" NOT "http://www.example.com/Prod/Spec/1115?dep=82&cat=243&tab=2"
Could anyone tell me how to have Facebook Like Button in ASP .NET MVC website with C# please?
You can create an image button of the like button first and then ..associate a label with it with the incremented integer value. If u want to to store it in database u can also do that.
You could go to the Facebook site dedicated to this button, generate the code and copy it into your layout page (or into view page, as you wish). The process is absolutely the same as for any other technology.
Okay, the task is pretty the same. You just need to put the generated code into the csthml and change slightly the url. For example you generate the following code
<div class="fb-like" data-href="http://www.mysite.com" data-send="false" data-layout="button_count" data-width="450" data-show-faces="false" data-action="recommend" data-font="lucida grande"></div>
you could create some variable like:
#{
string page url = #Url.Action("ProductSpec", "Products", new {id= item.Id})
}
and then replace the url in you link:
<div class="fb-like" data-href=#url data-send="false" data-layout="button_count" data-width="450" data-show-faces="false" data-action="recommend" data-font="lucida grande"></div
Related
I am creating a Login page, where there'll be two buttons. One is submit type 'Sign-in' button and other is a redirecting button 'Sign-up' which gets the URL of a view of another controller.
This login page (View) belongs to Login Controller and the redirecting button should access the MemberSignup View of the SignUp Controller.
<p>
<input type="button" value="Sign Up" class="btn" onclick= "document.location.href='SignUp/MemberSignUp'";/>
</p>
while running the above code it is executing with the URL: ~/Login/SignUp/MemberSignUp. Thus giving an error as the Login controller should not be included.
Another aproach if you don't want to rely on JavaScript for links on buttons, you can simply use an anchor and style it, making it look like a button, using css.
Your button text
Just add a "/" before your url to indicate that the path is absolute, not relative : document.location.href='/SignUp/MemberSignUp'
Or use the razor method to generate the url (best method) : #Url.Action("MemberSignup", "SignUp");
One method is just to point to the correct URL, example below;
<p>
<a href="/SignUp/MemberSignUp" >Sign Up</a>
<p>
or as mentioned below you can use an ActionResult.
However the issue you're having with your code is that you're missing the leading / from your redirect.
Add the following helper method to your view:
#Html.ActionLink("Your link text here", "MemberSignUp", "SignUp")
Moreover if you want some styling you can type:
#Html.ActionLink("Your link text here", "MemberSignUp", "SignUp", null, new{ #class="your-class" })
You can use as ActionLink as below:
#Html.ActionLink("Sign Up", "MemberSignUp", "SignUp", null, new { #class="your-class" } })
I have a fairly simple page with a set of jQuery tabs, the content of some is called via ajax. I also have a search box in the masterpage in my header.
When I open the tabbed page the search box works fine. However once I have clicked on one of the ajax tabs the search box fails to work with an "Invalid Viewstate" yellow screen of death.
I believe this is because the ajax page is replacing the __VIEWSTATE hidden input with its own.
How can I stop this behaviour?
UPDATE: I have noticed that the YSOD only appears in IE and Chrome, Firefox doesn't seem to have the same issue. Although how the browser influences the ViewState, I'm not sure.
UPDATE: I've put a cut down version of the site that shows the issue here: http://dropbox.com/s/7wqgjqqdorgp958/stackoverflow.zip
The reason of such behavior is that you getting content of the ajaxTab.aspx page asynchronously and paste it into another aspx page. So you getting two instances of hidden fields with __VIEWSTATE name and when page posted back to server theirs values are mixing (might depends on how browser process multiple controls with same name on submit). To resolve this you can put second tab's content into a frame:
<div id="tabs">
<ul>
<li>Default Tab</li>
<li>ajax Content</li>
</ul>
<div id="tabs-1">
<p>
To replicate the error:
<ul>
<li>First use the search box top right to search to prove that code is ok</li>
<li>Then click the second ajax tab, and search again.</li>
<li>N.B. Chrome / IE give a state error, Firefox does not</li>
</ul>
</p>
</div>
<iframe id="tabs-2" src="ajaxTab.aspx" style="width:100%;" ></iframe>
</div>
Also, I'm not sure but this seems like error in the Web_UserControls_search control. In my opinion, NavBarSearchItemNoSearchItem_OnClick method must be refactored as below:
protected void NavBarSearchItemNoSearchItem_OnClick(object sender, EventArgs e)
{
var searchFieldTbx = NavBarSearchItemNo;
var navBarSearchCatHiddenField = NavBarSearchCatHiddenField;
var term = searchFieldTbx != null ? searchFieldTbx.Text : "";
if (term.Length > 0) //There is actually something in the input box we can work with
{
//Response.Redirect(Url.GetUrl("SearchResults", term));
Response.Redirect(ResolveClientUrl("~/Web/SearchResults.aspx?term=" + term + "&cat=" + navBarSearchCatHiddenField.Value));
}
}
Draw attention that we resolving client url when redirecting to search results page and instead of navBarSearchCatHiddenField use navBarSearchCatHiddenField.Value as cat parameter.
I guess that you use AJAX to fill the content of the tab. So in this case, content of your tab will be replaced by the new one from ajax and certainly _VIEWSTATE will be replaced. At server, do you use data from ViewState? In the "static tabs", you should prevent them auto reload by using cache:true
Your issue is that with your ajax call you bring in a complete ASPX page. Including the Form tag and its Viewstate. If you remove the Form tag from ajaxTab.aspx you will see everything works fine. asp.net does not know how to handle two Form tags in one page. Same goes for hidden Viewstate fields. You cannot bring in a full aspx page via ajax. Just bring in the content Div you want to display and you`ll be good to go.
I want to link my winforms application to Facebook fanpage,So that a +1 is added when the user clicks the Like button on the Form .How can do it in C# winforms.Is it possible by invoking a URL.
You can get some LIKE button code: http://developers.facebook.com/docs/reference/plugins/like/ it will give you a few options, then you have a choice of delivery formats - choose IFRAME.
you'll get something that looks like this:
<iframe src="//www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.webbod.info&send=false&layout=standard&width=450&show_faces=false&action=like&colorscheme=light&font&height=35" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:35px;" allowTransparency="true">
</iframe>
You are only interested in the src and the dimensions.
In your winforms application you can host a webbrowser control size it to the dimensions and point it at the src - this will give you an embedded facebook like button.
Facebook allows people to Like URLs, so you'll need to provide one - in my example it's www.webbod.info, but anything should do and by varying the href part of the src url you can let people like any part of the application.
I have found this great class for sending POST request to a webpage. Now I tried it on a test page with single form and it works. But now I would like to do a POST request to a page, that has multiple forms on the same page. Is it possible to select specific form, if it is defined with name?
For example, like this:
<form method="post" action="index.php" target="_parent">
...
</form>
<form method="post" action="index.php" name="login" target="_top" class="login">
// This is the form that I want to post data
...
<input value="Go" type="submit" id="input_go" />
</form>
EDIT:
This solution provided by Anfurny does not work:
post.PostItems.Add("login", "input_go");
I have updated code, the button that submits has only id defined.
EDIT2:
I have found a good example of a page with two forms. phpMyAdmin demo, it has two forms, one is for selecting different language, the other is for login. This demo has:
username = root
password is empty
Now I have tried to login programmatically with this code (it uses class that I have posted the link on start of the page):
// First we create an instance of a class PostSubmitter.
PostSubmitter post = new PostSubmitter();
// We set the URL to which the POST should go.
post.Url = "http://demo.phpmyadmin.net/STABLE/index.php";
// We add items (password and username).
post.PostItems.Add("pma_username", "root");
post.PostItems.Add("pma_password", "");
// Also tried to add to which login form should post and the
// value set to id of the submit button, no luck.
//post.PostItems.Add("login_form", "input_go");
// Here we set the method.
post.Type = PostSubmitter.PostTypeEnum.Post;
// Getting back the result.
string result = post.Post();
// Writting it to the file.
TextWriter tw = new StreamWriter("C:/response.txt");
tw.WriteLine(result);
tw.Close();
The response.txt file has the same content as the login page, where it should have the code of the welcome page. Now how can I change code, to successfully login?
Usually when you have multiple forms posting to the same place, that you would differentiate them with the button that was clicked. Can you not do the same and add a virtual button (action) to your post list of values?
Have you tried doing something like this:
post.PostItems.Add("FORM_NAME","SUBMIT_BUTTON_NAME ");
?
Where FORM_NAME is the name of the form you wish to submit, and SUBMIT_BUTTON_NAME is the name of the submit button you wish to pretend was pressed (if more than one is present).
What is the best way to POST to another website (so that the users browser is redirected as well) in MVC2? I dont want the user to be able to see the form data simply by using "view source", so I'm not keen on
<form action="http://other-site.com/action">
<%= Html.TextBox("something-secret") %>
</form>
Is it instead possible (or advisable) to use an controller action? eg
public ActionResult PostTheData()
{
return Post("http://other-site.com/action", "something-secret");
}
You can use this persons code: http://geekswithblogs.net/rakker/archive/2006/04/21/76044.aspx
to post data to the other server. And after that use Redirect(url) to redirect to the page as well.