|
Hi,
I am trying to set the length of a field to a pre-defined certain value. For this reason I am padding right incase it is not the required lenght. for example
String1 = "Trailer1"
String2 = "Tra"
String1.ToString.PadRight(6) = "Traile" - should get me this value
String2.ToString.PadRight(6) = "Tra " - should get me this value.
Is it correct to use padright to limit the length of string?
Thanks so much for your time.
|
|
|
|
|
PadRight will not limit the length it will only pad it.
You example is not correct, but if you did:
String1.ToString.PadRight(6) = "Traile1" you would still get all seven characters. If you want to get only six characters you will need to substring after the padright
String1.ToString.PadRight(6).Substring(0,6)
Hope that helps.
Ben
|
|
|
|
|
Dear All,
I am mess with one situation let me explain the scenario.
I am making search form where I display 15 field in checkboxlist and user select one or two or three or any no to all field. Depending on his selection (he tick the field and click filter button ) Now in filter button click I create label and dropdownlist control(populated from database) and add it to placeholder control. Now I select value and click the search button. Now in search button I need to access those control and its selected value(ie label and droplistbox ).
I have made function to create label and dropdownlistbox which is
private void createcontrols()
{
foreach (ListItem li in CheckBoxListmst.Items)
{
if (li.Selected == true)
{
//code added to fetch dropdownlist
setting = ConfigurationManager.ConnectionStrings["StyleSearchConnectionString"];
if (setting != null)
{
Code to access data for populating dropdownlistbox
try
{
// added controls
Label label = new Label();
DropDownList dropdownlist = new DropDownList();
label.ID = "label" + i.ToString();
dropdownlist.ID = "dropdownlist" + .ToString();
i++;
rdr = cmd.ExecuteReader();
while (rdr.Read())
{
Items for dropdownlist
}
PlaceHolder1.Controls.Add(label);
PlaceHolder1.Controls.Add(dropdownlist);
}
catch (SqlException ex)
{
}
Now this create function I call in one in filter button click event and second as
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
createcontrols();
}
Now in seach button click event when I am trying to access
Code is
Label objlbl;
DropDownList objdrop;
objlbl = this.Page.FindControl("label1") as Label;
objdrop = this.Page.FindControl("dropdownlist1") as DropDownList;if ((objlbl != null) && (objdrop != null))
{
cmd.Parameters.Add("@para1", SqlDbType.VarChar).Value = objlbl.Text; //Page.FindControl("label1").ToString() ;
cmd.Parameters.Add("@value1", SqlDbType.VarChar).Value = objdrop.SelectedValue;
}
I am getting objlbl and objdrop as null.
Please help
thanks
imaran khan
|
|
|
|
|
You will have to search the PlaceHolder control and not the page. You will have to do a PlaceHolder1.FindControl(controlid)
Label objLabel = PlaceHolder1.FindControl("Label1") as Label;
DropDownList objDropDown = PlaceHolder1.FindControl("dropdownlist1") as DropDownList;
Tarakeshwar Reddy
MCP, CCIE Q(R&S)
There are two kinds of people, those who do the work and those who take the credit. Try to be in the first group; there is less competition there. - Indira Gandhi
|
|
|
|
|
did the same but still object are null even i check it for control id they are same.
please help
imaran khan
|
|
|
|
|
FindControl() should return the control. Did you debug and check if the PlaceHolder contains the controls? Debug and check the id of the control's that are in the PlaceHolder .
Tarakeshwar Reddy
MCP, CCIE Q(R&S)
There are two kinds of people, those who do the work and those who take the credit. Try to be in the first group; there is less competition there. - Indira Gandhi
|
|
|
|
|
You may need to call createcontrols() from Init rather than OnLoad. The problem is that on postback, the values in your checkboxes are saved in viewstate, which gets applied between Init and Load. If you wait until Load to create your controls, the viewstate won't be applied to them, and they'll lose their values.
|
|
|
|
|
i change the code and put it in Oninit as
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
createcontrols();
}
but still oject are null....
please help
imaran khan
|
|
|
|
|
My fix isn't for the problem you have (objects are null) but for the next problem you'll encounter (objects won't maintain values on if you dynamically create them too late in the page cycle).
The other solution posted to search the placeholder rather than the page for the controls should work, so I'm not sure what's wrong. I would use the debugger to inspect the contents of the placeholder's controls to see if anything is there.
|
|
|
|
|
I have aspx pages sitting in two different folders and both are mapped in virtual directory. I want to use response.redirect. How would I go about doing that?
|
|
|
|
|
Response.Redirect(Server.MapPath("FolderName\\FileName.aspx"));
I Love SQL
|
|
|
|
|
Edit: Bah. problem has been fixed.
--
Hi, I have a slight problem with getting records from a database.
The problem is simply when I use the following SQL string, it throws me up an error message.
Problem string:
"SELECT * FROM IDs WHERE id='2'"
However when I use this SQL string, it works.
Working SQL string:
"SELECT * FROM IDs WHERE name='bob'"
I have no idea why one is working and the other isn't. The only thing I could think of is a type mismatch (The id field is set to AutoNumber). I get the same error when trying to use both Strings and Integers.
Anyone have any ideas?
- Munty
-- modified at 10:20 Thursday 26th July, 2007
|
|
|
|
|
Muntyness wrote: it throws me up an error message
What error message it return?
I Love SQL
|
|
|
|
|
Ahhh goddammint!
I figured out what the problem was.
I was using "SELECT * FROM IDs WHERE id='2'" when I should have been using "SELECT * FROM IDs WHERE id=2".
|
|
|
|
|
Have you tried:
"SELECT * FROM IDs WHERE id=2"
|
|
|
|
|
Hello All,
Need your help with regards to SSO(Single Sign On). Lets say I have two websites A and B. After user logs on to A(login.aspx) user needs to go a say a default.aspx page and on Default.aspx, there is a button which on click should send the user to website B,(both websites are on the same domain..lets say a.abc.com and b.abc.com) as user is already logged on site A..it should directly send the user to welcome.aspx page on site B. Iam using form authentication. This is what i have in my web.config on both sites.
<authentication mode="Forms">
<forms name=".SSOAUTH" loginUrl="Login.aspx" protection="All" path="/" timeout="30"/>
</authentication>
<authorization>
<deny users="?"/>
<allow users="*"/>
</authorization>
<machineKey validationKey="1234567890" decryptionKey="9876543243" validation="SHA1"/>
On my site A login page, when user enters a login and password, i call a function and go against my DB and validate, if login and pwd match db, i return customerid and the code is as below:
Dim customerid As String = ValidateUser(txtUserName.Value, txtUserPass.Value)
If customerid <> "0" Then '--------Comment-if login is fine, customerid is never 0
Dim tkt As FormsAuthenticationTicket
Dim cookiestr As String
Dim ck As HttpCookie
tkt = New FormsAuthenticationTicket(1, txtUserName.Value, DateTime.Now, DateTime.Now.AddMinutes(30), True, "your custom data")
cookiestr = FormsAuthentication.Encrypt(tkt)
Session("FormData") = cookiestr '------Comment-saving in session for later use
Dim b As String = FormsAuthentication.FormsCookieName
Response.Cookies(b).Domain = .abc.com
Response.Cookies(b)("SiteA") = cookiestr
Response.Cookies(b).Expires = tkt.Expiration
Response.Cookies(b).Path = FormsAuthentication.FormsCookiePath
Response.Redirect("default.aspx")
Dim strRedirect As String
strRedirect = Request("ReturnURL")
If strRedirect <> "" Then
Response.Redirect(strRedirect, True)
Else
strRedirect = "Default.aspx"
Response.Redirect(strRedirect, True)
End If
Else
Response.Redirect("Login.aspx", True)
End If
My problem is it never redirects to Default.aspx on Site A... and from default.aspx on Site A..if i click a button..i need to it go to welcome.aspx on site B... for some weird reason though, it goes back to the login page..and further.. the cookie is set..its not reading it on site B. Please Help !! Any help is appreciated, where am i going wrong? code samples are much appreciated.
RH
|
|
|
|
|
I'm looking the code or codes of parameters in Crystal Report that I can access using C #. I appreciate your help.
|
|
|
|
|
|
with 'OWC .NET testpages demo app' depending on the option I select in:
'OWC demoss:
Scatter chart demo
OWC chart types
OWC chart with trendline and errorbars
I get 'could not load type: main.aspx
owctypes.aspx
trend.aspx
any ideas?
john
|
|
|
|
|
Hi ,
I am trying 3rd party authentication in my web application.
I am trying to use Google, Yahoo, AOL authentication providers. These authentication processes I am using to authenticate my application. I've done authentication for GMAIL.
In this authentication I've done following steps
1.Registered in GMAIL and mentioned destination page for remote authentication.
2.Used URL of Gmail authentication in my code and redirected to it
3.After entering correct credentials I retrieve TOKEN
4.Extract this TOKEN in destination page which I've mentioned in 1st step and with that Token I am calling Web service of GMAIL and retrieve User Details form it and showing on that page.
It is working fine for GOOGLE but from nowhere I am getting process/steps of how to use third party authentication for OPENID.
Please tell me if you know how to authenticate it.
Abhishek J
|
|
|
|
|
Hi All
I have created a folder which I want to rename through coding. If some knows the procedure then pls help me.
thanks in Advance.
|
|
|
|
|
Use the System.IO.Directory.Move or the System.IO.DirectoryInfo.MoveTo method.
---
single minded; short sighted; long gone;
|
|
|
|
|
Hi,
I think the possible way to rename the folder is to delete the folder and create the new folder with the new name, before deleting the old folder we should move he contents of that folder to new folder.
Regards,
Sandeep Kumar.V
|
|
|
|
|
System.IO.DirectoryInfo dInfo = new System.IO.DirectoryInfo(Server.MapPath("1"));<br />
if (dInfo.Exists)<br />
{<br />
System.IO.Directory.Move(Server.MapPath("1"), Server.MapPath("2"));<br />
}<br />
I just tried it.Its working fine
Here "1" is folder name
Best Regard
Khan
---------------------------------------------------
|
|
|
|
|
Thank u all of u, its realy helpfull. I have done my work. Once again thanks
|
|
|
|