here is what i have. a sharepoint page that has a textbox and a search button. the textbox data is tied to all of my tables and fills them in according to the company code typed into the textbox.
i'm trying to add a url that will also take the user out to a new page where they will see a sharepoint list filtered on the company code they entered in the original textbox.
so far i can make the url go to whatever company i choose by hardcoding the url like this:
http://mysite/Lists/Call%20Log/Company%20by%20Category.aspx?View={7C16BC72-8F1A-457A-9908-AF9E66DE97DC}&FilterField1=LinkTitle&FilterValue1=abccompany
for whatever reason i am unable to or can't figure out how to set filtervalue1 = <<text from textbox>>.
here is a sample of the code:
<WebPartPages:SPProxyWebPartManager runat="server" id="ProxyWebPartManager">
</WebPartPages:SPProxyWebPartManager>
Enter the CO ID and click "Search"
<asp:TextBox runat="server" id="tb_coID" Width="83px"></asp:TextBox>
<asp:Button runat="server" Text="Search" id="Button1"/>
<a target="_blank" href="http://site/Lists/Call%20Log/Company%20by%20Category.aspx?View={7C16BC72-8F1A-457A-9908-AF9E66DE97DC}&FilterField1=LinkTitle&FilterValue1=<<text from textbox here>>">
Click Here </a>to view Call Logs
in case anyeone else is looking this is the answer to my question that i figured out.
<script type="text/javascript">
function showReport() {
var coid = document.getElementById('ctl00_PlaceHolderMain_tb_coID').value;
window.open("http://site/Lists/Call%20Log/Company%20by%20Category.aspx?View= {7C16BC72-8F1A-457A-9908-AF9E66DE97DC}&FilterField1=LinkTitle&FilterValue1=" + coid, "_blank");
}
</script>
<WebPartPages:SPProxyWebPartManager runat="server" id="ProxyWebPartManager">
</WebPartPages:SPProxyWebPartManager>Enter the CO ID and click "Search"
<asp:TextBox runat="server" id="tb_coID" Width="83px"></asp:TextBox>
<asp:Button runat="server" Text="Search" id="Button1"/> & nbsp;
Click Here to view Call Logs related to this Company<br>
<br>
i just had to add these lines of code to the top of my page and it works amazingly
Related
I have a problem with losing my files on FileUpload in ASP.NET Web Forms. I am making a website which contains a form where a pdf page and an image should be uploaded by user, and previewed, but when they choose a headline text, font name and font size below uploads, those controls refresh my page and all of the uploaded files are lost. I have tried to add enctype="multipledata" in the form, but it did not work. Does anyone have a clue? Thanks in advance.
<script type="text/javascript">
function ShowImageBackPreview(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#<%=imagePreview.ClientID%>').prop('src', e.target.result)
.width(240)
.height(150);
};
reader.readAsDataURL(input.files[0]);
}
}
</script>
<asp:FileUpload ID="uploadImage" runat="server" CssClass="uploads" onchange="ShowImageBackPreview(this)" />
<asp:Image ID="imagePreview" Height="150px" Width="250px" runat="server" />
<asp:TextBox ID="txtName" runat="server" AutoPostBack="true" placeholder="Name"></asp:TextBox>
<asp:TextBox ID="txtSurname" runat="server" AutoPostBack="true" placeholder="Surname"></asp:TextBox>
When I start to enter the name and the surname, the uploaded shown image is disappeared and also the file path, on each entered text it refreshes the page.
Remove the autopostback for the controls txtName and txtSurName.
A auto post back means the page will post back when you change the values in those controls, and when you post-back, then the file is up-loaded, and your image preview will be lost.
You need a final up-load button on your page that when clicked on will run your code. That upload button can then grab the file up-loaded. You can't have autopostbacks for the text box controls as you show, but then again, there should NOT be ANY requirement for those text box controls to have autopostback=true.
So, remove your autopostback for the controls, and you should be fine.
I Have A Asp.net DropDownList return Data from a 1st table and insert to 2nd table we are inserting Name, Age and position to the 2nd table which the position is returning data from 1st table. the question is where there was a new record we will first add in the 1st table then refresh the page to be able to get the new record. is there is a way when click on dropdownlist at the end of the existing record will be a button "add new" and when click open a popup add new record after that the record add in a 1st table and also be available in the dropdownlist without refresh the page.
is this possible?
Everything up to the issue of NOT wanting to re-fresh the page was great.
How big of a deal is a page post back? I mean if you have several buttons on that form, then the page should be able to tolerate a post back. The reason for this issue/question/point is that WHEN you can allow post-backs, then you have a LOT of options and options that allow a lot of freedom to shove in a dialog pop-up that lets you add a new value to the combo box. And keep in mind that pop option to add a new row to the combo box (dropdownlist) will have to be re-bound with the just newly added row.
If push comes to shove and you REALLY can't tolrate the postback, then you can place the combo box and the "add" to combo box in a update panel.
Next up:
Because we want to pop a dialog? I would recommend adopting jQuery.UI. You have a good chance that jQuery is already included in your project, and thus adopting jQuery.UI is not much more.
There are bootstrap dialogs also - but they are really difficult to work with.
So, lets lay out how this will work.
So, assume we have a little bit of markup a few text boxes, and that dropdown.
Say this:
<div style="padding:5px;float:left;width:250px;text-align:right">
Hotel Name: <asp:TextBox ID="txtHotelName" runat="server" Width="130px" />
<br />
First Name: <asp:TextBox ID="txtFirst" runat="server" Width="130px" />
<br />
Last Name: <asp:TextBox ID="txtLast" runat="server" Text ='<%# Eval("LastName") %>' Width="130px" />
<br />
<div>
City : <asp:DropDownList ID="cboCity" runat="server" DataTextField="City"
DataValueField="City" Width="110px">
</asp:DropDownList>
<div style="float:right;text-align:center;margin-left:4px;margin-top:-1px">
<asp:Button ID="cmdAddCity" runat="server" Text="+"
OnClientClick="AddCity();return false"
style="padding-left:4px;padding-right:8px;width:12px;height:16px;Font-Size:8px"
/>
</div>
</div>
Active: <asp:CheckBox ID="chkActive" runat="server" Checked = '<%# Eval("Active") %>'/>
</div>
Not much to above, and we get this:
Of course on page load, I filled the drop list with code. I have this:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If IsPostBack = False Then
LoadCombo
End If
End Sub
Sub LoadCombo()
Using cmdSQL As New SqlCommand("SELECT City from tblCity ORDER BY City", New SqlConnection(My.Settings.TEST3))
cmdSQL.Connection.Open()
cboCity.DataSource = cmdSQL.ExecuteReader
cboCity.DataBind()
End Using
End Sub
As noted, we do tend to write statup + load up code in the page load event, but note how I test for ONLY the first post back. Thus, you can quite much write pages that can "survie" a post back.
Ok, so now we need a popup for the jQuery.UI. These are nice, since we don't have to create a whole new web page. The markup for this pop up form (a div) in the current page can/will look like this:
<div id="CityDialog" style="display:Normal" title="Add New City">
<br />
<asp:TextBox ID="txtNewCity" runat="server" Placeholder="Enter New City" ClientIDMode="Static" ></asp:TextBox>
<br />
<br />
<asp:Button ID="cmdOkAddCity" runat="server" Text="Add" ClientIDMode="Static" />
<asp:Button ID="cmdCityCancel" runat="server" Text="Cancel" ClientIDMode="Static"
OnClientClick="$('#CityDialog').dialog('close');return false;"
style="margin-left:20px"/>
</div>
So we add a title to the div. a text box for the new city to add. And two simple standard asp.net buttons.
So, we add above to the above page. and then double click on the cmdOkAdd button, and write the code to add a new row to the combo box.
That code looks like this:
Protected Sub cmdOkAddCity_Click(sender As Object, e As EventArgs) Handles cmdOkAddCity.Click
If txtNewCity.Text <> "" Then
Using cmdSQL As New SqlCommand("INSERT INTO tblCity (City) VALUES (#City)", New SqlConnection(My.Settings.TEST3))
cmdSQL.Parameters.Add("#City", SqlDbType.NVarChar).Value = txtNewCity.Text
cmdSQL.Connection.Open()
cmdSQL.ExecuteNonQuery()
' re-load combo
LoadCombo()
'
' set cbo to the new value we just added
cboCity.Text = txtNewCity.Text
End Using
End If
End Sub
Again, real simple code. (and all easy code behind so far). So what above does is check if the user did enter that new city into the text box, and if yes, then we add the row to the database, and then re-load the combo box and then we SET the combo box to the new city just added. This makes for a easy flow, as the user can then click on that little "+" button beside the combo box, and we pop a dialog, and then the user enters the city, and hits the ok button to run above code stub.
Ok, now we have to setup the jQuery.UI. yes, this is a WEE bit of JavaScript, but NOT much.
So, that "+" button beside the drop down? It is a regular asp button, it is going to pop that jQuery.UI dialog. That button looks like this:
<asp:Button ID="cmdAddCity" runat="server" Text="+"
OnClientClick="AddCity();return false"
style="padding-left:4px;padding-right:8px;width:12px;height:16px;Font-Size:8px"
/>
Note how we have OnClientClick= - that's going to run our JavaScript code stub.
So, say right after that last tag, we have this code:
</form>
<script>
function AddCity() {
$("#CityDialog").dialog({
modal: true,
width: "220px",
resizable: false,
appendTo: "form"
});
}
</script>
Not much code. What that code does it pop the "div" as a nice way cool dialog form. And it turns the rest of the background into a "disabled gray".
So, it works well. And last but not least? We have to hide that dialog div. Remember, don't hide it at first, since we need to double click on the Ok button (add city button) to wire up our add event. Once done, then we hide that div by changing display:normal to Display:none. Eg this:
<div id="CityDialog" style="display:none" title="Add New City">
<br />
<asp:TextBox ID="txtNewCity" runat="server" Placeholder="Enter New City" ClientIDMode="Static" ></asp:TextBox>
<br />
<br />
<asp:Button ID="cmdOkAddCity" runat="server" Text="Add" ClientIDMode="Static" />
... etc. etc.
Ok, now with the above? Well, then we now have this setup:
The code was very helpful but When add all code The popup is not triggering, the second thing How make the dropdown ID connected to the city table ID column not the city column this is my code: Download The Code
I have a repeater on my page, page1, which displays product details in each item. Each item has "select this" button and I post to page2. I want to display which product selected on page2. Sounds simple but couldn't solve it for hours. Any idea? My itemtemplate on page1 looks like this:
<ItemTemplate>
<ul>
<li><%#Eval("Product_Name") %></li>
<li><%#Eval("Product_Code") %></li>
...
<li>
<asp:Button ID="btnSubmit" runat="server" Text="Select this" PostBackUrl="page2"/></li>
</ul>
</ItemTemplate>
Only solution came to my mind getting button number with Request.Form but this will make me add one more query to get nth product. Thanks for help
Not sure it would apply to your situation, but usually, this problem is solved by using the ItemCommand pattern :
First subscribe to ItemCommand event of your repeater (same as subscribing to ItemCreated/ItemDataBound)
yourRepeater.ItemCommand += yourRepeater_ItemCommandHandler;
where the handler is :
protected void ItemCommandHandler(object source, RepeaterCommandEventArgs e)
{
if(e.CommandName=="SelectThis")
{
var productCode = e.CommandArgument;
//...
}
}
then, in your markup :
<asp:Button ID="btnSubmit" runat="server" Text="Select this" CommandName="SelectThis" CommandArgument='<%#Eval("Product_Code")%>' />
never tried this pattern when posting to another page. Hope this will help anyway.
Is a PostBack necessary? If not i suggest you to solve this problem with this approach:
Replace your asp:Button with asp:HyperLink and pass productId or productCode in a QueryString. Here's an example:
<ItemTemplate>
<ul>
.
.
<li>
<asp:HyperLink ID="hlSelectProduct" runat="server" Text="Select this" NavigateUrl='<%# string.Format("~/Page2.aspx?Product_Code={0}", Eval("Product_Code")) %>' />
</li>
</ul>
</ItemTemplate>
and on page2.aspx just retrieve product from database by using Product_Code
I cannot use querystrings because I don't want everything to be shown on url. And I tried ItemCommand but it requires page to post itself. For the same reason, I couldn't use onclientclick either.
However, I managed to solve the problem by using Jquery. I created a hiddenfield outside of repeater and created a jquery function to handle button clicks. I put the product id value in each buttons' rel attribute and assigned it to hiddentext's val by that function. Jquery function did work before page post and since my buttons all have postbackurl addresses, it worked without problem.
I am using a linkbutton within a gridview control.I want to open the data into a new tab.I tried to set target="_blank".
But it is not working.
I have tried doing this.This is my source code:
<asp:LinkButton ID="LinkButton1" runat="server"
CommandArgument="<%# Container.DataItemIndex %>" CommandName="###"
Font-Underline="False" Text='<%# Eval("###") target="_blank" %>' />
Please guide me and give me suggestions where I am doing wrong.
Page_Load use:
btnSubmit.Attributes.Add("href", "https://google.com/");
btnSubmit.Attributes.Add("target", "_blank");
Or use javascript:
<asp:LinkButton id="lnkTitle" runat="server" OnClientClick="return NewWindow();" OnClick="lnkTitle_Click" > Open Window</asp:LinkButton>
<script type="text/javascript">
function NewWindow() {
document.forms[0].target = '_blank';
}
</script>
Good successs =))
At most you can make it open into a new window and depending on the users internet settings it will open in a new tab. There's no way to make it open in a new tab though.
http://www.webmaster-talk.com/html-forum/32504-hyperlink-target-open-in-new-tab.html
Also check out this page:
how to open a page in new tab on button click in asp.net?
<asp:HyperLink ID="jiraLink" runat="server" Target="_blank">Click Here</asp:HyperLink>
Target="_blank" does the trick for me. Either try:
Capital "T" for target
Or, in the code behind, try:
jiraLink.Target = "_blank";
Also, it looks like you may have left the ending tick mark off (or misplaced) your Text field.
If you use
OnClientClick="window.open('/folder/Report.aspx');
in your LinkButton it opens in a new tab, but it does so on left click. Right click and selecting open in new tab will also open in new tab.
With with Linkbutton the user cannot control the target.
My case is I have an asp.net page has a form
<form id="form1" runat="server" target="_blank">
and a button redirect to another page and this page will open in a new window because of the target attribute of the form .
<asp:Button ID="button1" runat="server" PostBackUrl="~/kindofpage.aspx" Text="Generate" />
and I have a dropdownlist has auto postback = true to post the past to fill another dropdownlist by selected data .
<asp:dropdownliast id="Make" name="Make" runat="server" autopostback="true"></asp:dropdownlist>
the question is : why when I select item from the auto postbacked dropdown an blank page opened ?
I need a way to post the page by the dropdownlist without openning a blank page ..
Thank you,
For lack of a better idea, you could just remove the target="_blank" attribute from your markup, and when your button is clicked, modify the form tag with JavaScript and set the attribute.
You can set the OnClientClick property and run JavaScript when it's clicked. For example:
<asp:Button ID="button1" OnClientClick="document.getElementById('form1').setAttribute('target', '_blank')" runat="server" PostBackUrl="~/kindofpage.aspx" Text="Generate" />
You could always just adjust your buttonpress code to open a new window such as this:
<asp:Button ID="myBtn" runat="server" Text="Click me"
onclick="myBtn_Click" OnClientClick="window.open('kindofpage.aspx', 'kindofpage');" />
then remove the:
target="_blank"
From the form tag.
I struggled with a similar situation but solved it in the following way.
As mentioned in this answer, you can use the OnClientClick property to set the target to "_blank". E.g.
<asp:Button ID="button1" OnClick="codebehind_method" OnClientClick="document.forms[0].target = '_blank';" runat="server" Text="targets new window" />
Then, in the aspx page that my "codebehind_method" function redirects to, I reset the target of the opener form like so:
<script type="text/javascript">
function resetTarget() {
opener.document.forms[0].target = '';
}
</script>
<body onload="resetTarget()">
Now, if you go back to your opener form and use a control that does not have the "OnClientClick" property set, the AutoPostBack should occur in the same tab.
If you want to find your form by ID, replace "document.forms[0]" with:
document.getElementByID('yourFormName')
<form id="form1" runat="server">