Finding page id of parent form from pop up form - asp.net-4.0

I have two pages
Master page
page using the master page
I am opening a pop up using "window.open" in the second page.
I have textbox control in the second page and trying the find the control in the pop up page using below code.
window.opener.document.getElementById('textbox').value
This code could not found out the control.
Then I checked the page source of second form and dound out the format of control id. It was like below.
"_ctl0_ContentPlaceHolder1_textbox"
and changed the code to below and got success.
"window.opener.document.getElementById('_ctl0_ContentPlaceHolder1_textbox').value"
My query is -> I am not about this approach. Please correct if i am doing anything wrong.

With ASP.NET 4.0 you have the option to set ClientIDMode that could help you in this case.
Setting ClientIDMode to "Static" will ensure that your ID value will not be altered by the framework.
In your page where you have textbox:
<asp:TextBox ID="MyTextBox" runat="server" ClientIDMode="Static" />
Then you should be able to get the value by doing something like this:
window.opener.document.getElementById('textbox').value
Ref: MSDN - ClientIDMode

The problem is that if you use a masterpage the controls of your contentpage will be renamed making it hard to access them from JavaScript.
Use the following code to solve the problem:
<asp:TextBox ID="textbox" runat="server" ClientIDMode="Static"></asp:TextBox>

Related

Linking VB.Net Repeaters to Profile Pages

SOCIAL NETWORK PROJECT.
This is the code placed inside the repeater:
<asp:HyperLink ID="HyperLink1" runat="server"
NavigateUrl='<%# Eval("uname", "~/XsProfile.aspx?uname={0}") %>'>
<%# Eval("uname")%>
</asp:HyperLink>
The code will generate links for x number of times.
On clicking on the link,
It redirects to that person's profile.
Details need to be fetched on the person's profile.
What would go in the following code to achieve this output?
<asp:AccessDataSource ID="fav_music_data" runat="server"
DataFile="~/paperhome_data.accdb"
SelectCommand="SELECT * FROM [userinfo]
WHERE ([uname] = *****?*****)">
</asp:AccessDataSource>
What exactly goes into 'WHERE' clause?
Since your URL has ?uname= the answer should be in ASP.NET's Request object. You might be able to use Request("uname") but that's generally frowned upon.
A malicious user could enter their username as:
''; drop table userinfo;
...and very bad things could happen to your site.
I appreciate that you're trying to do your work simply (e.g. using declarative datasources) but at some point you're probably going to need to write some code.

SharePoint 2010 Site Customization: Removed breadcrumb and now receiving errors

I removed the following fields from the "s4-titletext" cell using the Manage Content Regions in SPD:
PlaceHolderSiteName
PlaceHolderPageTitleInTitleArea
PlaceHolderPageDescription
And I added "SharePoint:SPLinkButton... Visible="False"
I have published this template and have set it as the Default Master. It displays fine but when I add a web part (not in SPD), I get the error "You must specify a value for this required field" and it will not let me add/remove the web part or change any list. What did I do wrong in my customization? I followed the instructions on this post. I used Option 2 to hide the words. The reason I removed the fields is because I want to stretch our banner across the whole page and I didn't want to leave the space where the bread crumb would have been. My "s4-titletext" area looks like the pictures on the top of the page, only banner is stretched all across the top of page. I can not add a link to my page due to it being on a private server. I have asked other SharePoint experts and they are stumped as well. Thank you for your help on this.
Instead of setting visible="false", getting hiding the control using a CSS class. Set the control's class to something like 'hiddenClass' and then define your class style.
.hiddenClass{display: none;}
Customizing SharePoint masterpages is a pain since they're so sensitive. You have to use this method when hiding a lot of the out of the box controls.
Some placeholders need to be on the master page, if you remove it it will cause errors in some of the scrips.
What I recommend to you is create a hidden div and inside of it put all the placeholder you want to hide, like the example bellow.
<div style="display:none">
<asp:ContentPlaceHolder ID="TitleZone" runat="server"></asp:ContentPlaceHolder>
<div>

Using FileUpload in DNN Setting.ascx possible?

first time asking a question here.
I'm making a DNN module and in the Setting.ascx I'm trying to add any form of FileUpload in there. I'm successful at adding ASP's FileUpload as well as Telerik's RadUpload, but when I click a button I added to save and examine the uploaded the file it's empty and no longer holding any data. I thought I was coding it wrong at first, but after adding it into the View.ascx instead it works perfectly. Of course that's not where I want it to be.
I believe the problem might be how the Setting.ascx works in DNN. I believe it's using a form of AJAX to display it so that might be interfering. Hard to say though. While I'm at it can anyone confirm that Setting.ascx is using AJAX and that button clicks cause asynchronous postbacks? Thanks.
You're right with your thought that the form uses AJAX (formerly via UpdatePanel, now via RadAjaxPanel in DNN 6.x), and that's what's interfering with the upload. In most scenarios, you'd just switch to a regular postback by calling ScriptManager.RegisterPostBackControl, but in the settings case, you don't have a direct reference to the LinkButton that saves the settings.
You'll probably need to add your own button to the form to do the upload after the user has selected the file. DNN's own UrlControl uses a system like that, where there's an Upload button next to the Browse button. DNN also has a newer DnnFilePicker control, which might also encapsulate what you want. You'll just need to add an # Register directive to use those. For example:
<%# Reference tagPrefix="dnn" tagName="UrlControl" Src="~/controls/URLControl.ascx" %>
<%# Reference tagPrefix="dnn" Assembly="DotNetNuke.Web" Namespace="DotNetNuke.Web.UI.WebControls" %>
<dnn:UrlControl runat="server" ID="FileUpload"
ShowLog="false"
ShowNewWindow="false"
ShowTrack="false"
ShowImages="false"
ShowNone="false"
ShowTabs="false"
ShowUrls="false"
ShowUsers="false"
ShowFiles="false"
ShowUpLoad="true" />
<dnn:DnnFilePicker runat="server" ID="FilePicker"
FileFilter="jpg,png,gif" />
Man, just don't put a updatepanel outside your ascx control
If you need to use updatepanel, put it inside the ascx. That will resolve your problem!
I was able to solve this problem by doing the following:
Create my own submit button as opposed to relying on the "Save" button built into the page
Adding the following to my LoadSettings() method:
ScriptManager.GetCurrent(this.Page).RegisterPostBackControl(cmdUpload);
Where cmdUpload is the ID of my submit button.
You will need to add a reference to System.Web and System.Web.Extensions for this to compile.

Is that true that we can't create a browse button in sharepoint?

Hello guys I am stuck at a point and i want ur help.First of all i want to clear that i am not a sharepoint developer but my boss gave me a task which i have to complete in 2 days . I want you ppl to help me to accomplish this task.I have two questions in my mind
1) Is that true that we can't create a browse button in sharepoint?
2) If there is a way to create browse button in sharepoint then pls explain here.And if not then what should i do to get browse button in sharepoint.
EDIT:-
I want a browse button like in picture,onclick which opens file uplod dialog.
Here's the picture.
No that is not true. You can put any html in your web parts, master pages, or page layouts:
<input name="uploadedfile" type="file" />
There is also an ASP.NET file upload button available, like so:
<asp:FileUpload runat="server" id="FileUpload1" />
The "official" SharePoint way to do it would probably be having a document library in your site and doing this with javascript:
NewItem2(event, "/path/to/list/NewForm.aspx?PageType=8&ListId={fdcbd17c-9b66-449e-8875-d25de53f98d1}&RootFolder=");javascript:return false;
and if you have a web part (or any C#) generating this javascript, you should use the document library's DefaultNewFormUrl

Sharepoint FormField validation

I have
<SharePoint:FormField
ID="id"
runat="server"
ControlMode="New"
FieldName="FName" >
</SharePoint:FormField>
in the webpart, and a asp.net button on it.
the field is required field. when i click the button the validation does't perform.
how can i validate the field.
It is possible, by calling FormField.Validate(); and FormField.IsValid
But you have to return the outcome of this validation manually to the user. I have not yet found a better solution.